fixed github issue 3819 for endpoint customizer tests (#3823)
* fixed github issue 3819 for endpoint customizer tests * added negative test cases * improved comments * using ahrav's approach
This commit is contained in:
@@ -8,9 +8,53 @@ import (
|
||||
|
||||
func TestEmbeddedEndpointSetter(t *testing.T) {
|
||||
type Scanner struct{ EndpointSetter }
|
||||
|
||||
var s Scanner
|
||||
assert.Equal(t, []string{"baz"}, s.Endpoints("baz"))
|
||||
assert.NoError(t, s.SetConfiguredEndpoints("foo", "bar"))
|
||||
assert.Error(t, s.SetConfiguredEndpoints())
|
||||
assert.Equal(t, []string{"foo", "bar"}, s.Endpoints("baz"))
|
||||
|
||||
t.Run("useFoundEndpoints is true", func(t *testing.T) {
|
||||
s.useFoundEndpoints = true
|
||||
|
||||
// "baz" is passed to Endpoints, should appear in the result
|
||||
assert.Equal(t, []string{"baz"}, s.Endpoints("baz"))
|
||||
})
|
||||
|
||||
t.Run("setting configured endpoints", func(t *testing.T) {
|
||||
// Setting "foo" and "bar"
|
||||
assert.NoError(t, s.SetConfiguredEndpoints("foo", "bar"))
|
||||
|
||||
// Returning error because no endpoints are passed
|
||||
assert.Error(t, s.SetConfiguredEndpoints())
|
||||
})
|
||||
|
||||
// "foo" and "bar" are added as configured endpoint
|
||||
|
||||
t.Run("useFoundEndpoints adds new endpoints", func(t *testing.T) {
|
||||
// "baz" is added because useFoundEndpoints is true
|
||||
assert.Equal(t, []string{"foo", "bar", "baz"}, s.Endpoints("baz"))
|
||||
})
|
||||
|
||||
t.Run("useCloudEndpoint is true", func(t *testing.T) {
|
||||
s.useCloudEndpoint = true
|
||||
s.cloudEndpoint = "test"
|
||||
|
||||
// "test" is added because useCloudEndpoint is true and cloudEndpoint is set
|
||||
assert.Equal(t, []string{"foo", "bar", "test"}, s.Endpoints())
|
||||
})
|
||||
|
||||
t.Run("disable both foundEndpoints and cloudEndpoint", func(t *testing.T) {
|
||||
// now disable both useFoundEndpoints and useCloudEndpoint
|
||||
s.useFoundEndpoints = false
|
||||
s.useCloudEndpoint = false
|
||||
|
||||
// "test" won't be added
|
||||
assert.Equal(t, []string{"foo", "bar"}, s.Endpoints("test"))
|
||||
})
|
||||
|
||||
t.Run("cloudEndpoint not added when useCloudEndpoint is false", func(t *testing.T) {
|
||||
s.cloudEndpoint = "new"
|
||||
|
||||
// "new" is not added because useCloudEndpoint is false
|
||||
assert.Equal(t, []string{"foo", "bar"}, s.Endpoints())
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user