Skip to content

Commit

Permalink
Revise the error message for selector object verification (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardChen820 authored Jul 11, 2024
1 parent 4ac752e commit eff5fea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
},
}

Expect(verifyObject(configProviderSpec).Error()).Should(Equal("spec.configuration.selectors: set both keyFilter and snapshotName in one selector causes ambiguity, only one of them should be set"))
Expect(verifyObject(configProviderSpec).Error()).Should(Equal("spec.configuration.selectors: set both 'keyFilter' and 'snapshotName' in one selector causes ambiguity, only one of them should be set"))

configProviderSpec2 := acpv1.AzureAppConfigurationProviderSpec{
ConnectionStringReference: &connectionStringReference,
Expand All @@ -1038,7 +1038,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
},
}

Expect(verifyObject(configProviderSpec2).Error()).Should(Equal("spec.configuration.selectors: labelFilter is not allowed when snapshotName is set"))
Expect(verifyObject(configProviderSpec2).Error()).Should(Equal("spec.configuration.selectors: 'labelFilter' is not allowed when 'snapshotName' is set"))

configProviderSpec3 := acpv1.AzureAppConfigurationProviderSpec{
ConnectionStringReference: &connectionStringReference,
Expand All @@ -1054,7 +1054,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
},
}

Expect(verifyObject(configProviderSpec3).Error()).Should(Equal("spec.configuration.selectors: one of keyFilter and snapshotName field must be set"))
Expect(verifyObject(configProviderSpec3).Error()).Should(Equal("spec.configuration.selectors: a selector uses 'labelFilter' but misses the 'keyFilter', 'keyFilter' is required for key-label pair filtering"))
})
})

Expand Down
6 changes: 3 additions & 3 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ func verifyWorkloadIdentityParameters(workloadIdentity *acpv1.WorkloadIdentityPa

func verifySelectorObject(selector acpv1.Selector) error {
if selector.KeyFilter == nil && selector.SnapshotName == nil {
return fmt.Errorf("one of keyFilter and snapshotName field must be set")
return fmt.Errorf("a selector uses 'labelFilter' but misses the 'keyFilter', 'keyFilter' is required for key-label pair filtering")
}

if selector.SnapshotName != nil {
if selector.KeyFilter != nil {
return fmt.Errorf("set both keyFilter and snapshotName in one selector causes ambiguity, only one of them should be set")
return fmt.Errorf("set both 'keyFilter' and 'snapshotName' in one selector causes ambiguity, only one of them should be set")
}
if selector.LabelFilter != nil {
return fmt.Errorf("labelFilter is not allowed when snapshotName is set")
return fmt.Errorf("'labelFilter' is not allowed when 'snapshotName' is set")
}
}

Expand Down

0 comments on commit eff5fea

Please sign in to comment.