@@ -40,12 +40,14 @@ func (noopEventProcessor) On(_ ...api.Resource) {}
4040func (noopEventProcessor ) Done (_ string , _ bool ) {}
4141
4242const (
43- ipamOptionsProjectName = "test"
44- ipamOptionsNetworkKey = "default"
45- ipamOptionsNetworkName = "test_default"
46- ipamOptionsKey = "test"
47- ipamOptionsValue = "1"
48- ipamOptionsCreatedNetID = "net1"
43+ executorTestProjectName = "test"
44+ executorTestNetworkKey = "default"
45+ executorTestNetworkName = "test_default"
46+ executorTestNetworkResource = "network:" + executorTestNetworkKey
47+ executorTestNotFoundCause = "not found"
48+ executorTestCreatedNetworkID = "net1"
49+ ipamOptionsKey = "test"
50+ ipamOptionsValue = "1"
4951)
5052
5153func newTestService (t * testing.T ) (* composeService , * mocks.MockAPIClient ) {
@@ -62,80 +64,80 @@ func newTestService(t *testing.T) (*composeService, *mocks.MockAPIClient) {
6264
6365func TestExecutePlanEmpty (t * testing.T ) {
6466 svc , _ := newTestService (t )
65- err := svc .executePlan (t .Context (), & types.Project {Name : "test" }, emptyObservedState ("test" ), & Plan {})
67+ err := svc .executePlan (t .Context (), & types.Project {Name : executorTestProjectName }, emptyObservedState (executorTestProjectName ), & Plan {})
6668 assert .NilError (t , err )
6769}
6870
6971func TestExecutePlanCreateNetwork (t * testing.T ) {
7072 svc , apiClient := newTestService (t )
7173
72- nw := types.NetworkConfig {Name : "test_default" }
74+ nw := types.NetworkConfig {Name : executorTestNetworkName }
7375 project := & types.Project {
74- Name : "test" ,
75- Networks : types.Networks {"default" : nw },
76+ Name : executorTestProjectName ,
77+ Networks : types.Networks {executorTestNetworkKey : nw },
7678 }
7779
7880 // ensureNetwork: inspect → not found, list → empty, create
79- apiClient .EXPECT ().NetworkInspect (gomock .Any (), "test_default" , gomock .Any ()).
81+ apiClient .EXPECT ().NetworkInspect (gomock .Any (), executorTestNetworkName , gomock .Any ()).
8082 Return (client.NetworkInspectResult {}, notFoundError {})
8183 apiClient .EXPECT ().NetworkList (gomock .Any (), gomock .Any ()).
8284 Return (client.NetworkListResult {}, nil )
83- apiClient .EXPECT ().NetworkCreate (gomock .Any (), "test_default" , gomock .Any ()).
84- Return (client.NetworkCreateResult {ID : "net1" }, nil )
85+ apiClient .EXPECT ().NetworkCreate (gomock .Any (), executorTestNetworkName , gomock .Any ()).
86+ Return (client.NetworkCreateResult {ID : executorTestCreatedNetworkID }, nil )
8587
8688 plan := & Plan {}
8789 plan .addNode (Operation {
8890 Type : OpCreateNetwork ,
89- ResourceID : "network:default" ,
90- Cause : "not found" ,
91+ ResourceID : executorTestNetworkResource ,
92+ Cause : executorTestNotFoundCause ,
9193 Name : nw .Name ,
9294 Network : & nw ,
9395 }, "" )
9496
95- err := svc .executePlan (t .Context (), project , emptyObservedState ("test" ), plan )
97+ err := svc .executePlan (t .Context (), project , emptyObservedState (executorTestProjectName ), plan )
9698 assert .NilError (t , err )
9799}
98100
99101func TestExecutePlanCreateNetworkWithIPAMOptions (t * testing.T ) {
100102 svc , apiClient := newTestService (t )
101103
102104 nw := types.NetworkConfig {
103- Name : ipamOptionsNetworkName ,
105+ Name : executorTestNetworkName ,
104106 Ipam : types.IPAMConfig {
105107 Options : types.Options {
106108 ipamOptionsKey : ipamOptionsValue ,
107109 },
108110 },
109111 }
110112 project := & types.Project {
111- Name : ipamOptionsProjectName ,
112- Networks : types.Networks {ipamOptionsNetworkKey : nw },
113+ Name : executorTestProjectName ,
114+ Networks : types.Networks {executorTestNetworkKey : nw },
113115 }
114116
115- apiClient .EXPECT ().NetworkInspect (gomock .Any (), ipamOptionsNetworkName , gomock .Any ()).
117+ apiClient .EXPECT ().NetworkInspect (gomock .Any (), executorTestNetworkName , gomock .Any ()).
116118 Return (client.NetworkInspectResult {}, notFoundError {})
117119 apiClient .EXPECT ().NetworkList (gomock .Any (), gomock .Any ()).
118120 Return (client.NetworkListResult {}, nil )
119- apiClient .EXPECT ().NetworkCreate (gomock .Any (), ipamOptionsNetworkName , gomock .Any ()).
121+ apiClient .EXPECT ().NetworkCreate (gomock .Any (), executorTestNetworkName , gomock .Any ()).
120122 DoAndReturn (func (_ context.Context , _ string , opts client.NetworkCreateOptions ) (client.NetworkCreateResult , error ) {
121123 assert .DeepEqual (t , opts .IPAM , & network.IPAM {
122124 Options : map [string ]string {
123125 ipamOptionsKey : ipamOptionsValue ,
124126 },
125127 })
126- return client.NetworkCreateResult {ID : ipamOptionsCreatedNetID }, nil
128+ return client.NetworkCreateResult {ID : executorTestCreatedNetworkID }, nil
127129 })
128130
129131 plan := & Plan {}
130132 plan .addNode (Operation {
131133 Type : OpCreateNetwork ,
132- ResourceID : "network:" + ipamOptionsNetworkKey ,
133- Cause : "not found" ,
134+ ResourceID : executorTestNetworkResource ,
135+ Cause : executorTestNotFoundCause ,
134136 Name : nw .Name ,
135137 Network : & nw ,
136138 }, "" )
137139
138- err := svc .executePlan (t .Context (), project , emptyObservedState (ipamOptionsProjectName ), plan )
140+ err := svc .executePlan (t .Context (), project , emptyObservedState (executorTestProjectName ), plan )
139141 assert .NilError (t , err )
140142}
141143
0 commit comments