@@ -83,22 +83,71 @@ networks:
83
83
}
84
84
85
85
func TestResetCycle (t * testing.T ) {
86
- _ , err := Load (
87
- types.ConfigDetails {
88
- ConfigFiles : []types.ConfigFile {
89
- {
90
- Filename : "(inline)" ,
91
- Content : []byte (`
86
+ tests := []struct {
87
+ name string
88
+ config string
89
+ expectError bool
90
+ errorMsg string
91
+ }{
92
+ {
93
+ name : "no cycle" ,
94
+ config : `
95
+ name: test
96
+ services:
97
+ a: &a
98
+ image: alpine
99
+ a2: *a
100
+ ` ,
101
+ expectError : false ,
102
+ errorMsg : "" ,
103
+ },
104
+ {
105
+ name : "no cycle reversed" ,
106
+ config : `
107
+ name: test
108
+ services:
109
+ a2: &a
110
+ image: alpine
111
+ a: *a
112
+ ` ,
113
+ expectError : false ,
114
+ errorMsg : "" ,
115
+ },
116
+ {
117
+ name : "healthcheck_cycle" ,
118
+ config : `
92
119
x-healthcheck: &healthcheck
93
120
egress-service:
94
121
<<: *healthcheck
95
- ` ),
96
- },
97
- },
98
- }, func (options * Options ) {
99
- options .SkipNormalization = true
100
- options .SkipConsistencyCheck = true
122
+ ` ,
123
+ expectError : true ,
124
+ errorMsg : "cycle detected at path: x-healthcheck.egress-service" ,
101
125
},
102
- )
103
- assert .Error (t , err , "cycle detected at path: x-healthcheck.egress-service" )
126
+ }
127
+
128
+ for _ , tt := range tests {
129
+ t .Run (
130
+ tt .name , func (t * testing.T ) {
131
+ _ , err := Load (
132
+ types.ConfigDetails {
133
+ ConfigFiles : []types.ConfigFile {
134
+ {
135
+ Filename : "(inline)" ,
136
+ Content : []byte (tt .config ),
137
+ },
138
+ },
139
+ }, func (options * Options ) {
140
+ options .SkipNormalization = true
141
+ options .SkipConsistencyCheck = true
142
+ },
143
+ )
144
+
145
+ if tt .expectError {
146
+ assert .Error (t , err , tt .errorMsg )
147
+ } else {
148
+ assert .NilError (t , err )
149
+ }
150
+ },
151
+ )
152
+ }
104
153
}
0 commit comments