55 "os"
66 "testing"
77
8- ".. /proxy"
8+ "github.com/docker-flow/docker-flow-proxy /proxy"
99 "github.com/stretchr/testify/mock"
1010 "github.com/stretchr/testify/suite"
1111)
@@ -24,12 +24,12 @@ func (s *ReconfigureTestSuite) SetupTest() {
2424 sd := proxy.ServiceDest {
2525 ServicePath : []string {"path/to/my/service/api" , "path/to/my/other/service/api" },
2626 Index : 0 ,
27+ PathType : "path_beg" ,
2728 }
2829 s .InstanceName = "proxy-test-instance"
2930 s .ServiceDest = []proxy.ServiceDest {sd }
3031 s .ConfigsPath = "path/to/configs/dir"
3132 s .TemplatesPath = "test_configs/tmpl"
32- s .PathType = "path_beg"
3333 s .reconfigure = Reconfigure {
3434 BaseReconfigure : BaseReconfigure {
3535 TemplatesPath : s .TemplatesPath ,
@@ -40,7 +40,7 @@ func (s *ReconfigureTestSuite) SetupTest() {
4040 ServiceName : s .ServiceName ,
4141 AclName : s .ServiceName ,
4242 ServiceDest : []proxy.ServiceDest {sd },
43- PathType : s . PathType ,
43+ Replicas : 1 ,
4444 },
4545 }
4646 os .Setenv ("SKIP_ADDRESS_VALIDATION" , "true" )
@@ -122,6 +122,7 @@ func (s ReconfigureTestSuite) Test_GetTemplates_UsesServerTemplate_WhenDiscovery
122122 s .reconfigure .Service .ServiceDest [0 ].Port = "1234"
123123 s .reconfigure .Service .DiscoveryType = "DNS"
124124 s .reconfigure .Service .Replicas = 0
125+ s .reconfigure .Service .IsGlobal = true
125126 expected := `
126127backend myService-be1234_0
127128 mode http
@@ -428,6 +429,7 @@ backend https-myService-be4321_0
428429 s .reconfigure .ServiceDest [0 ].Port = "1234"
429430 s .reconfigure .ServiceDest [0 ].HttpsPort = 4321
430431 s .reconfigure .Replicas = 0
432+ s .reconfigure .IsGlobal = true
431433 s .reconfigure .DiscoveryType = "DNS"
432434 actualFront , actualBack , _ := s .reconfigure .GetTemplates ()
433435
@@ -739,7 +741,8 @@ func (s ReconfigureTestSuite) Test_Execute_WritesServerSession() {
739741 s .reconfigure .AclName = "my-service"
740742 s .reconfigure .ServiceDest [0 ].Port = "1111"
741743 s .reconfigure .ServiceDest [0 ].HttpsPort = 2222
742- s .reconfigure .Tasks = []string {"1.2.3.4" , "4.3.2.1" }
744+ // The expectedData will place these ips in order
745+ s .reconfigure .Tasks = []string {"4.3.2.1" , "1.2.3.4" }
743746 s .reconfigure .SessionType = "sticky-server"
744747 var actualData string
745748 expectedData := `
@@ -1033,6 +1036,19 @@ func (s ReconfigureTestSuite) Test_Execute_RemovesService_WhenProxyFails() {
10331036 mockObj .AssertCalled (s .T (), "RemoveService" , s .ServiceName )
10341037}
10351038
1039+ func (s ReconfigureTestSuite ) Test_Execute_RemovesService_WhenReplicasIs0 () {
1040+ s .reconfigure .Service .Replicas = 0
1041+
1042+ mockObj := getProxyMock ("" )
1043+ proxyOrig := proxy .Instance
1044+ defer func () { proxy .Instance = proxyOrig }()
1045+ proxy .Instance = mockObj
1046+
1047+ s .reconfigure .Execute (true )
1048+
1049+ mockObj .AssertCalled (s .T (), "RemoveService" , s .ServiceName )
1050+ }
1051+
10361052func (s ReconfigureTestSuite ) Test_Execute_ReloadsAgain_WhenProxyFails () {
10371053 mockObj := getProxyMock ("Reload" )
10381054 mockObj .On ("Reload" ).Return (fmt .Errorf ("This is an error" ))
@@ -1052,11 +1068,12 @@ func (s ReconfigureTestSuite) Test_Execute_AddsService() {
10521068 proxy .Instance = mockObj
10531069 sd := proxy.ServiceDest {
10541070 ServicePath : []string {"path/to/my/service/api" , "path/to/my/other/service/api" },
1071+ PathType : "path_beg" ,
10551072 }
10561073 expected := proxy.Service {
10571074 ServiceName : "s.ServiceName" ,
10581075 ServiceDest : []proxy.ServiceDest {sd },
1059- PathType : s . PathType ,
1076+ Replicas : 1 ,
10601077 }
10611078 r := NewReconfigure (
10621079 BaseReconfigure {
@@ -1135,12 +1152,13 @@ func (s *ReconfigureTestSuite) Test_Execute_WhenFilterProxyInstanceIsTrue_SamePr
11351152 proxy .Instance = mockObj
11361153 sd := proxy.ServiceDest {
11371154 ServicePath : []string {"path/to/my/service/api" , "path/to/my/other/service/api" },
1155+ PathType : "path_beg" ,
11381156 }
11391157 expected := proxy.Service {
11401158 ServiceName : s .ServiceName ,
11411159 ServiceDest : []proxy.ServiceDest {sd },
1142- PathType : s .PathType ,
11431160 ProxyInstanceName : s .InstanceName ,
1161+ Replicas : 1 ,
11441162 }
11451163 r := NewReconfigure (
11461164 BaseReconfigure {
@@ -1167,11 +1185,11 @@ func (s *ReconfigureTestSuite) Test_Execute_WhenFilterProxyInstanceIsTrue_Differ
11671185 proxy .Instance = mockObj
11681186 sd := proxy.ServiceDest {
11691187 ServicePath : []string {"path/to/my/service/api" , "path/to/my/other/service/api" },
1188+ PathType : "path_beg" ,
11701189 }
11711190 expected := proxy.Service {
11721191 ServiceName : s .ServiceName ,
11731192 ServiceDest : []proxy.ServiceDest {sd },
1174- PathType : s .PathType ,
11751193 ProxyInstanceName : "another-docker-flow" ,
11761194 }
11771195 r := NewReconfigure (
0 commit comments