@@ -139,3 +139,73 @@ deploy:
139139 assert .Equal (t , "main" , config .Include [3 ].Ref )
140140 assert .Equal (t , "/templates/.gitlab-ci-template.yml" , config .Include [3 ].File [0 ])
141141}
142+
143+ func TestGitlabIncludes (t * testing.T ) {
144+ subjects := []struct {
145+ config string
146+ expected GitlabciIncludeItems
147+ }{
148+ {
149+ config : `include: https://example.com` ,
150+ expected : []GitlabciIncludeItem {
151+ {Remote : "https://example.com" },
152+ },
153+ },
154+ {
155+ config : `include: local.yml` ,
156+ expected : []GitlabciIncludeItem {
157+ {Local : "local.yml" },
158+ },
159+ },
160+ {
161+ config : `include: [https://example.com]` ,
162+ expected : []GitlabciIncludeItem {
163+ {Remote : "https://example.com" },
164+ },
165+ },
166+ {
167+ config : `include: [local.yml]` ,
168+ expected : []GitlabciIncludeItem {
169+ {Local : "local.yml" },
170+ },
171+ },
172+ {
173+ config : `include: [{local: local.yml}]` ,
174+ expected : []GitlabciIncludeItem {
175+ {Local : "local.yml" },
176+ },
177+ },
178+ {
179+ config : `include: [{remote: http://example.com}]` ,
180+ expected : []GitlabciIncludeItem {
181+ {Remote : "http://example.com" },
182+ },
183+ },
184+ {
185+ config : `include: [{template: Auto-DevOps.gitlab-ci.yml}]` ,
186+ expected : []GitlabciIncludeItem {
187+ {Template : "Auto-DevOps.gitlab-ci.yml" },
188+ },
189+ },
190+ {
191+ config : `include: [{project: my-group/my-project, ref: main, file: /templates/.gitlab-ci-template.yml}]` ,
192+ expected : []GitlabciIncludeItem {
193+ {
194+ Project : "my-group/my-project" ,
195+ Ref : "main" ,
196+ File : []string {"/templates/.gitlab-ci-template.yml" },
197+ },
198+ },
199+ },
200+ {
201+ config : `{}` ,
202+ expected : nil ,
203+ },
204+ }
205+
206+ for _ , subject := range subjects {
207+ config , err := ParseGitlabciConfig ([]byte (subject .config ))
208+ assert .Nil (t , err )
209+ assert .Equal (t , subject .expected , config .Include )
210+ }
211+ }
0 commit comments