Skip to content

Commit

Permalink
always match base discriminator
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Sep 11, 2024
1 parent f49b539 commit bc1d049
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Model struct {
SourceFile string `json:"SourceFile,omitempty"`
TotalCount int `json:"TotalCount,omitempty"`
Type *string `json:"Type,omitempty"`
Variants *map[string]*Model `json:"Variants,omitempty"` // variant model name is used as key, this may only contains
Variants *map[string]*Model `json:"Variants,omitempty"` // variant model name is used as key, in case x-ms-discriminator-value is not available
VariantType *string `json:"VariantType,omitempty"` // the x-ms-discriminator-value of the variant model if exists, otherwise model name
}

Expand Down Expand Up @@ -171,14 +171,14 @@ func (m *Model) MarkCovered(root interface{}) {

// either the discriminator value hit the variant model name or variant type, we match the variant
if variant, ok := (*m.Variants)[v.(string)]; ok {
isMatchProperty = false
isMatchProperty = true
variant.MarkCovered(value)

break
}
for _, variant := range *m.Variants {
if variant.VariantType != nil && *variant.VariantType == v.(string) {
isMatchProperty = false
isMatchProperty = true
variant.MarkCovered(value)

break Loop
Expand Down
21 changes: 10 additions & 11 deletions coverage/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestCoverage_MachineLearningServicesWorkspacesJobs(t *testing.T) {
name: "MachineLearningServicesWorkspacesJobs",
resourceType: "Microsoft.MachineLearningServices/workspaces/jobs@2024-04-01",
method: "PUT",
expectedCoveredCount: 11,
expectedCoveredCount: 19,
expectedTotalCount: 895,
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/rg1/providers/Microsoft.MachineLearningServices/workspaces/works1/jobs/job1",
rawRequest: []string{
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestCoverage_MachineLearningServicesWorkspacesDataVersions(t *testing.T) {
name: "MachineLearningServicesWorkspacesDataVersions",
resourceType: "Microsoft.MachineLearningServices/workspaces/data/versions@2024-04-01",
method: "PUT",
expectedCoveredCount: 8,
expectedCoveredCount: 15,
expectedTotalCount: 29,
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/rg1/providers/Microsoft.MachineLearningServices/workspaces/works1/data/data1/versions/version1",
rawRequest: []string{
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestCoverage_DeviceSecurityGroup(t *testing.T) {
name: "DeviceSecurityGroup",
resourceType: "Microsoft.Security/deviceSecurityGroups@2019-08-01",
method: "PUT",
expectedCoveredCount: 5,
expectedCoveredCount: 10,
expectedTotalCount: 192,
apiPath: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SampleRG/providers/Microsoft.Devices/iotHubs/sampleiothub/providers/Microsoft.Security/deviceSecurityGroups/samplesecuritygroup",
rawRequest: []string{
Expand All @@ -243,7 +243,6 @@ func TestCoverage_DeviceSecurityGroup(t *testing.T) {
if err != nil {
t.Fatalf("process coverage: %+v", err)
}

}

func TestCoverage_SCVMM(t *testing.T) {
Expand Down Expand Up @@ -283,7 +282,7 @@ func TestCoverage_DataMigrationServiceTasks(t *testing.T) {
name: "DataMigrationServiceTasks",
resourceType: "Microsoft.DataMigration/services/serviceTasks@2021-06-30",
method: "PUT",
expectedCoveredCount: 2,
expectedCoveredCount: 3,
expectedTotalCount: 615,
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/DmsSdkRg/providers/Microsoft.DataMigration/services/DmsSdkService/serviceTasks/DmsSdkTask",
rawRequest: []string{
Expand Down Expand Up @@ -311,7 +310,7 @@ func TestCoverage_DataMigrationTasks(t *testing.T) {
name: "DataMigrationTasks",
resourceType: "Microsoft.DataMigration/services/projects/tasks@2021-06-30",
method: "PUT",
expectedCoveredCount: 8,
expectedCoveredCount: 9,
expectedTotalCount: 615,
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/DmsSdkRg/providers/Microsoft.DataMigration/services/DmsSdkService/projects/DmsSdkProject/tasks/DmsSdkTask",
rawRequest: []string{
Expand Down Expand Up @@ -1039,7 +1038,7 @@ func TestCoverage_CosmosDB(t *testing.T) {
name: "CosmosDB",
resourceType: "Microsoft.DocumentDB/databaseAccounts@2024-05-15",
method: "PUT",
expectedCoveredCount: 33,
expectedCoveredCount: 34,
expectedTotalCount: 67,
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/testdb",
rawRequest: []string{
Expand Down Expand Up @@ -1264,7 +1263,7 @@ func TestCoverage_DataFactoryPipelines(t *testing.T) {
name: "DataFactoryPipelines",
resourceType: "Microsoft.DataFactory/factories/pipelines@2018-06-01",
method: "PUT",
expectedCoveredCount: 11,
expectedCoveredCount: 13,
expectedTotalCount: 7239,
apiPath: "/subscriptions/12345678-1234-1234-1234-12345678abc/resourceGroups/exampleResourceGroup/providers/Microsoft.DataFactory/factories/exampleFactoryName/pipelines/examplePipeline",
rawRequest: []string{
Expand Down Expand Up @@ -1362,7 +1361,7 @@ func TestCoverage_DataFactoryLinkedServices(t *testing.T) {
name: "DataFactoryLinkedServices",
resourceType: "Microsoft.DataFactory/factories/linkedServices@2018-06-01",
method: "PUT",
expectedCoveredCount: 2,
expectedCoveredCount: 3,
expectedTotalCount: 3450,
apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/rg1/providers/Microsoft.DataFactory/factories/factory1/linkedServices/linked",
rawRequest: []string{
Expand Down Expand Up @@ -1397,8 +1396,8 @@ func TestCoverage_DataFactoryLinkedServices(t *testing.T) {
t.Fatalf("expected properties type property, got none")
}

if (*(*model.Properties)["properties"].Properties)["type"].IsAnyCovered {
t.Fatalf("expected properties type IsAnyCovered false, got true")
if !(*(*model.Properties)["properties"].Properties)["type"].IsAnyCovered {
t.Fatalf("expected properties type IsAnyCovered true, got false")
}

if (*model.Properties)["properties"].Discriminator == nil {
Expand Down

0 comments on commit bc1d049

Please sign in to comment.