88 "testing"
99
1010 "cuelang.org/go/cue"
11- "github.com/input-output-hk/catalyst-forge/lib/project/injector"
12- imocks "github.com/input-output-hk/catalyst-forge/lib/project/injector/mocks"
11+ "cuelang.org/go/cue/cuecontext"
1312 "github.com/input-output-hk/catalyst-forge/lib/tools/testutils"
1413 "github.com/spf13/afero"
1514 "github.com/stretchr/testify/assert"
@@ -44,49 +43,32 @@ func NewMockFileSeeker(s string) MockFileSeeker {
4443}
4544
4645func TestBlueprintLoaderLoad (t * testing.T ) {
47- defaultInjector := func () injector.Injector {
48- return injector .NewInjector (
49- slog .New (slog .NewTextHandler (io .Discard , nil )),
50- & imocks.EnvGetterMock {
51- GetFunc : func (name string ) (string , bool ) {
52- return "" , false
53- },
54- },
55- )
56- }
57-
5846 tests := []struct {
5947 name string
6048 fs afero.Fs
61- injector injector.Injector
62- overrider InjectorOverrider
6349 project string
6450 gitRoot string
6551 files map [string ]string
6652 cond func (* testing.T , cue.Value )
6753 expectErr bool
6854 }{
6955 {
70- name : "no files" ,
71- fs : afero .NewMemMapFs (),
72- injector : defaultInjector (),
73- overrider : nil ,
74- project : "/tmp/dir1/dir2" ,
75- gitRoot : "/tmp/dir1/dir2" ,
76- files : map [string ]string {},
56+ name : "no files" ,
57+ fs : afero .NewMemMapFs (),
58+ project : "/tmp/dir1/dir2" ,
59+ gitRoot : "/tmp/dir1/dir2" ,
60+ files : map [string ]string {},
7761 cond : func (t * testing.T , v cue.Value ) {
7862 assert .NoError (t , v .Err ())
7963 assert .NotEmpty (t , v .LookupPath (cue .ParsePath ("version" )))
8064 },
8165 expectErr : false ,
8266 },
8367 {
84- name : "single file" ,
85- fs : afero .NewMemMapFs (),
86- injector : defaultInjector (),
87- overrider : nil ,
88- project : "/tmp/dir1/dir2" ,
89- gitRoot : "/tmp/dir1/dir2" ,
68+ name : "single file" ,
69+ fs : afero .NewMemMapFs (),
70+ project : "/tmp/dir1/dir2" ,
71+ gitRoot : "/tmp/dir1/dir2" ,
9072 files : map [string ]string {
9173 "/tmp/dir1/dir2/blueprint.cue" : `
9274 version: "1.0"
@@ -113,12 +95,10 @@ func TestBlueprintLoaderLoad(t *testing.T) {
11395 expectErr : false ,
11496 },
11597 {
116- name : "multiple files" ,
117- fs : afero .NewMemMapFs (),
118- injector : defaultInjector (),
119- overrider : nil ,
120- project : "/tmp/dir1/dir2" ,
121- gitRoot : "/tmp/dir1" ,
98+ name : "multiple files" ,
99+ fs : afero .NewMemMapFs (),
100+ project : "/tmp/dir1/dir2" ,
101+ gitRoot : "/tmp/dir1" ,
122102 files : map [string ]string {
123103 "/tmp/dir1/dir2/blueprint.cue" : `
124104 version: "1.0"
@@ -157,96 +137,16 @@ func TestBlueprintLoaderLoad(t *testing.T) {
157137 },
158138 expectErr : false ,
159139 },
160- {
161- name : "with injection" ,
162- fs : afero .NewMemMapFs (),
163- injector : injector .NewInjector (
164- slog .New (slog .NewTextHandler (io .Discard , nil )),
165- & imocks.EnvGetterMock {
166- GetFunc : func (name string ) (string , bool ) {
167- if name == "RETRIES" {
168- return "5" , true
169- }
170-
171- return "" , false
172- },
173- },
174- ),
175- overrider : nil ,
176- project : "/tmp/dir1/dir2" ,
177- gitRoot : "/tmp/dir1/dir2" ,
178- files : map [string ]string {
179- "/tmp/dir1/dir2/blueprint.cue" : `
180- version: "1.0"
181- project: {
182- name: "test"
183- ci: {
184- targets: {
185- test: {
186- retries: _ @env(name=RETRIES,type=int)
187- }
188- }
189- }
190- }
191- ` ,
192- "/tmp/dir1/.git" : "" ,
193- },
194- cond : func (t * testing.T , v cue.Value ) {
195- assert .NoError (t , v .Err ())
196-
197- field , err := v .LookupPath (cue .ParsePath ("project.ci.targets.test.retries" )).Int64 ()
198- require .NoError (t , err )
199- assert .Equal (t , int64 (5 ), field )
200- },
201- expectErr : false ,
202- },
203- {
204- name : "with injection overrides" ,
205- fs : afero .NewMemMapFs (),
206- injector : defaultInjector (),
207- overrider : func (bp cue.Value ) map [string ]string {
208- return map [string ]string {
209- "RETRIES" : "5" ,
210- }
211- },
212- project : "/tmp/dir1/dir2" ,
213- gitRoot : "/tmp/dir1/dir2" ,
214- files : map [string ]string {
215- "/tmp/dir1/dir2/blueprint.cue" : `
216- version: "1.0"
217- project: {
218- name: "test"
219- ci: {
220- targets: {
221- test: {
222- retries: _ @env(name=RETRIES,type=int)
223- }
224- }
225- }
226- }
227- ` ,
228- "/tmp/dir1/.git" : "" ,
229- },
230- cond : func (t * testing.T , v cue.Value ) {
231- assert .NoError (t , v .Err ())
232-
233- field , err := v .LookupPath (cue .ParsePath ("project.ci.targets.test.retries" )).Int64 ()
234- require .NoError (t , err )
235- assert .Equal (t , int64 (5 ), field )
236- },
237- expectErr : false ,
238- },
239140 }
240141
241142 for _ , tt := range tests {
242143 t .Run (tt .name , func (t * testing.T ) {
243144 testutils .SetupFS (t , tt .fs , tt .files )
244145
245146 loader := DefaultBlueprintLoader {
246- fs : tt .fs ,
247- injector : tt .injector ,
248- logger : slog .New (slog .NewTextHandler (io .Discard , nil )),
249- overrider : tt .overrider ,
147+ ctx : cuecontext .New (),
148+ fs : tt .fs ,
149+ logger : slog .New (slog .NewTextHandler (io .Discard , nil )),
250150 }
251151
252152 bp , err := loader .Load (tt .project , tt .gitRoot )
0 commit comments