1- package configmanager_test
1+ package configmanager
22
33import (
44 "os"
55 "path/filepath"
66
77 . "github.com/onsi/ginkgo/v2"
88 . "github.com/onsi/gomega"
9-
10- "github.com/devstream-io/devstream/internal/pkg/configmanager"
119)
1210
1311const configFileStr = `---
@@ -98,35 +96,38 @@ pipelineTemplates:
9896var _ = Describe ("LoadConfig" , func () {
9997 var tmpWorkDir string
10098
101- tool1 := configmanager. Tool {
99+ tool1 := & Tool {
102100 Name : "plugin1" ,
103101 InstanceID : "default" ,
104- Options : configmanager.RawOptions {
102+ DependsOn : []string {},
103+ Options : RawOptions {
105104 "foo1" : "bar1" ,
106105 "instanceID" : "default" ,
107106 },
108107 }
109108
110- tool2 := configmanager. Tool {
109+ tool2 := & Tool {
111110 Name : "plugin2" ,
112111 InstanceID : "tluafed" ,
113- Options : configmanager.RawOptions {
112+ DependsOn : []string {},
113+ Options : RawOptions {
114+ "instanceID" : "tluafed" ,
114115 "foo" : "bar" ,
115116 "foo2" : "bar2" ,
116- "instanceID" : "default1" ,
117117 },
118118 }
119119
120- tool3 := configmanager. Tool {
120+ tool3 := & Tool {
121121 Name : "github-actions" ,
122122 InstanceID : "service-a" ,
123123 DependsOn : []string {
124124 "repo-scaffolding.service-a" ,
125125 },
126- Options : configmanager.RawOptions {
127- "pipeline" : configmanager.RawOptions {
128- "docker" : configmanager.RawOptions {
129- "registry" : configmanager.RawOptions {
126+ Options : RawOptions {
127+ "instanceID" : "service-a" ,
128+ "pipeline" : RawOptions {
129+ "docker" : RawOptions {
130+ "registry" : RawOptions {
130131 "repository" : "service-a" ,
131132 "type" : "dockerhub" ,
132133 "username" : "dockerUser1" ,
@@ -135,81 +136,81 @@ var _ = Describe("LoadConfig", func() {
135136 "branch" : "main" ,
136137 "configLocation" : "git@github.com:devstream-io/ci-template.git//github-actions" ,
137138 },
138- "scm" : configmanager. RawOptions {
139+ "scm" : RawOptions {
139140 "apiURL" : "gitlab.com/some/path/to/your/api" ,
140141 "owner" : "devstream-io" ,
141142 "org" : "devstream-io" ,
142143 "name" : "service-a" ,
143144 "scmType" : "github" ,
144145 "url" : "https://github.com/devstream-io/service-a" ,
145146 },
146- "instanceID" : "service-a" ,
147147 },
148148 }
149149
150- tool4 := configmanager. Tool {
150+ tool4 := & Tool {
151151 Name : "argocdapp" ,
152152 InstanceID : "service-a" ,
153153 DependsOn : []string {
154154 "repo-scaffolding.service-a" ,
155155 },
156- Options : configmanager.RawOptions {
157- "pipeline" : configmanager.RawOptions {
158- "destination" : configmanager.RawOptions {
156+ Options : RawOptions {
157+ "instanceID" : "service-a" ,
158+ "pipeline" : RawOptions {
159+ "destination" : RawOptions {
159160 "namespace" : "devstream-io" ,
160161 "server" : "https://kubernetes.default.svc" ,
161162 },
162- "app" : configmanager. RawOptions {
163+ "app" : RawOptions {
163164 "namespace" : "argocd" ,
164165 },
165- "source" : configmanager. RawOptions {
166+ "source" : RawOptions {
166167 "valuefile" : "values.yaml" ,
167168 "path" : "helm/service-a" ,
168169 "repoURL" : "${{repo-scaffolding.myapp.outputs.repoURL}}" ,
169170 },
170171 "configLocation" : "" ,
171172 },
172- "scm" : configmanager. RawOptions {
173+ "scm" : RawOptions {
173174 "url" : "https://github.com/devstream-io/service-a" ,
174175 "apiURL" : "gitlab.com/some/path/to/your/api" ,
175176 "owner" : "devstream-io" ,
176177 "org" : "devstream-io" ,
177178 "name" : "service-a" ,
178179 "scmType" : "github" ,
179180 },
180- "instanceID" : "service-a" ,
181181 },
182182 }
183183
184- tool5 := configmanager. Tool {
184+ tool5 := & Tool {
185185 Name : "repo-scaffolding" ,
186186 InstanceID : "service-a" ,
187- Options : configmanager.RawOptions {
188- "destinationRepo" : configmanager.RawOptions {
187+ DependsOn : []string {},
188+ Options : RawOptions {
189+ "instanceID" : "service-a" ,
190+ "destinationRepo" : RawOptions {
189191 "needAuth" : true ,
190192 "org" : "devstream-io" ,
191193 "repo" : "service-a" ,
192194 "branch" : "main" ,
193195 "repoType" : "github" ,
194196 "url" : "github.com/devstream-io/service-a" ,
195197 },
196- "sourceRepo" : configmanager. RawOptions {
198+ "sourceRepo" : RawOptions {
197199 "repoType" : "github" ,
198200 "url" : "github.com/devstream-io/dtm-scaffolding-golang" ,
199201 "needAuth" : true ,
200202 "org" : "devstream-io" ,
201203 "repo" : "dtm-scaffolding-golang" ,
202204 "branch" : "main" ,
203205 },
204- "vars" : configmanager. RawOptions {
206+ "vars" : RawOptions {
205207 "foo1" : "bar1" ,
206208 "foo2" : "bar2" ,
207209 "registryType" : "dockerhub" ,
208210 "framework" : "django" ,
209211 "language" : "python" ,
210212 "argocdNamespace" : "argocd" ,
211213 },
212- "instanceID" : "service-a" ,
213214 },
214215 }
215216
@@ -221,17 +222,17 @@ var _ = Describe("LoadConfig", func() {
221222
222223 When ("load a config file" , func () {
223224 It ("should return 5 tools" , func () {
224- mgr := configmanager . NewManager (filepath .Join (tmpWorkDir , "config.yaml" ))
225+ mgr := NewManager (filepath .Join (tmpWorkDir , "config.yaml" ))
225226 cfg , err := mgr .LoadConfig ()
226227 Expect (err ).NotTo (HaveOccurred ())
227228 Expect (cfg ).NotTo (BeNil ())
228229
229230 GinkgoWriter .Printf ("Config: %v" , cfg )
230231
231232 // config/state
232- Expect (* cfg .Config .State ).To (Equal (configmanager. State {
233+ Expect (* cfg .Config .State ).To (Equal (State {
233234 Backend : "local" ,
234- Options : configmanager. StateConfigOptions {
235+ Options : StateConfigOptions {
235236 StateFile : "devstream.state" ,
236237 },
237238 }))
@@ -261,3 +262,21 @@ var _ = Describe("LoadConfig", func() {
261262 })
262263 })
263264})
265+
266+ var _ = Describe ("escapeBrackets" , func () {
267+ When ("escape brackets" , func () {
268+ It ("should works right" , func () {
269+ testStrBytes1 := "foo: [[ foo ]]\n "
270+ testStr2 := "foo: xx[[ foo ]]\n "
271+ testStr3 := "foo: [[ foo ]]xx\n "
272+
273+ retStr1 := escapeBrackets ([]byte (testStrBytes1 ))
274+ retStr2 := escapeBrackets ([]byte (testStr2 ))
275+ retStr3 := escapeBrackets ([]byte (testStr3 ))
276+
277+ Expect (string (retStr1 )).To (Equal ("foo: \" [[ foo ]]\" \n " ))
278+ Expect (string (retStr2 )).To (Equal ("foo: xx[[ foo ]]\n " ))
279+ Expect (string (retStr3 )).To (Equal ("foo: \" [[ foo ]]xx\" \n " ))
280+ })
281+ })
282+ })
0 commit comments