@@ -41,12 +41,14 @@ func (noopEventProcessor) On(_ ...api.Resource) {}
4141func (noopEventProcessor ) Done (_ string , _ bool ) {}
4242
4343const (
44- ipamOptionsProjectName = "test"
45- ipamOptionsNetworkKey = "default"
46- ipamOptionsNetworkName = "test_default"
47- ipamOptionsKey = "test"
48- ipamOptionsValue = "1"
49- ipamOptionsCreatedNetID = "net1"
44+ executorTestProjectName = "test"
45+ executorTestNetworkKey = "default"
46+ executorTestNetworkName = "test_default"
47+ executorTestNetworkResource = "network:" + executorTestNetworkKey
48+ executorTestNotFoundCause = "not found"
49+ executorTestCreatedNetworkID = "net1"
50+ ipamOptionsKey = "ipam-option"
51+ ipamOptionsValue = "enabled"
5052)
5153
5254func newTestService (t * testing.T ) (* composeService , * mocks.MockAPIClient ) {
@@ -63,77 +65,73 @@ func newTestService(t *testing.T) (*composeService, *mocks.MockAPIClient) {
6365
6466func TestExecutePlanEmpty (t * testing.T ) {
6567 svc , _ := newTestService (t )
66- err := svc .executePlan (t .Context (), & types.Project {Name : "test" }, emptyObservedState ("test" ), & Plan {})
68+ err := svc .executePlan (t .Context (), & types.Project {Name : executorTestProjectName }, emptyObservedState (executorTestProjectName ), & Plan {})
6769 assert .NilError (t , err )
6870}
6971
7072func TestExecutePlanCreateNetwork (t * testing.T ) {
7173 svc , apiClient := newTestService (t )
7274
73- nw := types.NetworkConfig {Name : "test_default" }
75+ nw := types.NetworkConfig {Name : executorTestNetworkName }
7476 project := & types.Project {
75- Name : "test" ,
76- Networks : types.Networks {"default" : nw },
77+ Name : executorTestProjectName ,
78+ Networks : types.Networks {executorTestNetworkKey : nw },
7779 }
7880
7981 // createNetwork issues a plain NetworkCreate (divergence/reuse decisions are
8082 // made by the reconciler from the observed state, not here).
81- apiClient .EXPECT ().NetworkCreate (gomock .Any (), "test_default" , gomock .Any ()).
82- Return (client.NetworkCreateResult {ID : "net1" }, nil )
83+ apiClient .EXPECT ().NetworkCreate (gomock .Any (), executorTestNetworkName , gomock .Any ()).
84+ Return (client.NetworkCreateResult {ID : executorTestCreatedNetworkID }, nil )
8385
8486 plan := & Plan {}
8587 plan .addNode (Operation {
8688 Type : OpCreateNetwork ,
87- ResourceID : "network:default" ,
88- Cause : "not found" ,
89+ ResourceID : executorTestNetworkResource ,
90+ Cause : executorTestNotFoundCause ,
8991 Name : nw .Name ,
9092 Network : & nw ,
9193 }, "" )
9294
93- err := svc .executePlan (t .Context (), project , emptyObservedState ("test" ), plan )
95+ err := svc .executePlan (t .Context (), project , emptyObservedState (executorTestProjectName ), plan )
9496 assert .NilError (t , err )
9597}
9698
9799func TestExecutePlanCreateNetworkWithIPAMOptions (t * testing.T ) {
98100 svc , apiClient := newTestService (t )
99101
100102 nw := types.NetworkConfig {
101- Name : ipamOptionsNetworkName ,
103+ Name : executorTestNetworkName ,
102104 Ipam : types.IPAMConfig {
103105 Options : types.Options {
104106 ipamOptionsKey : ipamOptionsValue ,
105107 },
106108 },
107109 }
108110 project := & types.Project {
109- Name : ipamOptionsProjectName ,
110- Networks : types.Networks {ipamOptionsNetworkKey : nw },
111+ Name : executorTestProjectName ,
112+ Networks : types.Networks {executorTestNetworkKey : nw },
111113 }
112114
113- apiClient .EXPECT ().NetworkInspect (gomock .Any (), ipamOptionsNetworkName , gomock .Any ()).
114- Return (client.NetworkInspectResult {}, notFoundError {})
115- apiClient .EXPECT ().NetworkList (gomock .Any (), gomock .Any ()).
116- Return (client.NetworkListResult {}, nil )
117- apiClient .EXPECT ().NetworkCreate (gomock .Any (), ipamOptionsNetworkName , gomock .Any ()).
115+ apiClient .EXPECT ().NetworkCreate (gomock .Any (), executorTestNetworkName , gomock .Any ()).
118116 DoAndReturn (func (_ context.Context , _ string , opts client.NetworkCreateOptions ) (client.NetworkCreateResult , error ) {
119117 assert .DeepEqual (t , opts .IPAM , & network.IPAM {
120118 Options : map [string ]string {
121119 ipamOptionsKey : ipamOptionsValue ,
122120 },
123121 })
124- return client.NetworkCreateResult {ID : ipamOptionsCreatedNetID }, nil
122+ return client.NetworkCreateResult {ID : executorTestCreatedNetworkID }, nil
125123 })
126124
127125 plan := & Plan {}
128126 plan .addNode (Operation {
129127 Type : OpCreateNetwork ,
130- ResourceID : "network:" + ipamOptionsNetworkKey ,
131- Cause : "not found" ,
128+ ResourceID : executorTestNetworkResource ,
129+ Cause : executorTestNotFoundCause ,
132130 Name : nw .Name ,
133131 Network : & nw ,
134132 }, "" )
135133
136- err := svc .executePlan (t .Context (), project , emptyObservedState (ipamOptionsProjectName ), plan )
134+ err := svc .executePlan (t .Context (), project , emptyObservedState (executorTestProjectName ), plan )
137135 assert .NilError (t , err )
138136}
139137
0 commit comments