@@ -8,9 +8,53 @@ import (
8
8
9
9
func TestEmbeddedEndpointSetter (t * testing.T ) {
10
10
type Scanner struct { EndpointSetter }
11
+
11
12
var s Scanner
12
- assert .Equal (t , []string {"baz" }, s .Endpoints ("baz" ))
13
- assert .NoError (t , s .SetConfiguredEndpoints ("foo" , "bar" ))
14
- assert .Error (t , s .SetConfiguredEndpoints ())
15
- assert .Equal (t , []string {"foo" , "bar" }, s .Endpoints ("baz" ))
13
+
14
+ t .Run ("useFoundEndpoints is true" , func (t * testing.T ) {
15
+ s .useFoundEndpoints = true
16
+
17
+ // "baz" is passed to Endpoints, should appear in the result
18
+ assert .Equal (t , []string {"baz" }, s .Endpoints ("baz" ))
19
+ })
20
+
21
+ t .Run ("setting configured endpoints" , func (t * testing.T ) {
22
+ // Setting "foo" and "bar"
23
+ assert .NoError (t , s .SetConfiguredEndpoints ("foo" , "bar" ))
24
+
25
+ // Returning error because no endpoints are passed
26
+ assert .Error (t , s .SetConfiguredEndpoints ())
27
+ })
28
+
29
+ // "foo" and "bar" are added as configured endpoint
30
+
31
+ t .Run ("useFoundEndpoints adds new endpoints" , func (t * testing.T ) {
32
+ // "baz" is added because useFoundEndpoints is true
33
+ assert .Equal (t , []string {"foo" , "bar" , "baz" }, s .Endpoints ("baz" ))
34
+ })
35
+
36
+ t .Run ("useCloudEndpoint is true" , func (t * testing.T ) {
37
+ s .useCloudEndpoint = true
38
+ s .cloudEndpoint = "test"
39
+
40
+ // "test" is added because useCloudEndpoint is true and cloudEndpoint is set
41
+ assert .Equal (t , []string {"foo" , "bar" , "test" }, s .Endpoints ())
42
+ })
43
+
44
+ t .Run ("disable both foundEndpoints and cloudEndpoint" , func (t * testing.T ) {
45
+ // now disable both useFoundEndpoints and useCloudEndpoint
46
+ s .useFoundEndpoints = false
47
+ s .useCloudEndpoint = false
48
+
49
+ // "test" won't be added
50
+ assert .Equal (t , []string {"foo" , "bar" }, s .Endpoints ("test" ))
51
+ })
52
+
53
+ t .Run ("cloudEndpoint not added when useCloudEndpoint is false" , func (t * testing.T ) {
54
+ s .cloudEndpoint = "new"
55
+
56
+ // "new" is not added because useCloudEndpoint is false
57
+ assert .Equal (t , []string {"foo" , "bar" }, s .Endpoints ())
58
+ })
59
+
16
60
}
0 commit comments