@@ -3,6 +3,7 @@ package scaffold
33import (
44 "os"
55 "path/filepath"
6+ "runtime"
67 "testing"
78
89 "github.com/michaeldyrynda/arbor/internal/scaffold/types"
@@ -35,7 +36,9 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
3536 })
3637
3738 t .Run ("file_exists - file exists" , func (t * testing.T ) {
38- os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 )
39+ if err := os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 ); err != nil {
40+ t .Fatalf ("writing test file: %v" , err )
41+ }
3942
4043 result , err := evaluator .Evaluate (map [string ]interface {}{
4144 "file_exists" : "test.txt" ,
@@ -53,7 +56,9 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
5356 })
5457
5558 t .Run ("file_contains - file contains pattern" , func (t * testing.T ) {
56- os .WriteFile (filepath .Join (tmpDir , "composer.json" ), []byte (`{"name": "test/package"}` ), 0644 )
59+ if err := os .WriteFile (filepath .Join (tmpDir , "composer.json" ), []byte (`{"name": "test/package"}` ), 0644 ); err != nil {
60+ t .Fatalf ("writing composer.json: %v" , err )
61+ }
5762
5863 result , err := evaluator .Evaluate (map [string ]interface {}{
5964 "file_contains" : map [string ]interface {}{
@@ -66,7 +71,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
6671 })
6772
6873 t .Run ("file_contains - file does not contain pattern" , func (t * testing.T ) {
69- os .WriteFile (filepath .Join (tmpDir , "composer.json" ), []byte (`{"name": "other/package"}` ), 0644 )
74+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , "composer.json" ), []byte (`{"name": "other/package"}` ), 0644 ) )
7075
7176 result , err := evaluator .Evaluate (map [string ]interface {}{
7277 "file_contains" : map [string ]interface {}{
@@ -96,15 +101,26 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
96101
97102 t .Run ("os matches current OS" , func (t * testing.T ) {
98103 result , err := evaluator .Evaluate (map [string ]interface {}{
99- "os" : "darwin" ,
104+ "os" : runtime . GOOS ,
100105 })
101106 assert .NoError (t , err )
102107 assert .True (t , result )
103108 })
104109
105110 t .Run ("os does not match current OS" , func (t * testing.T ) {
111+ var otherOS string
112+ switch runtime .GOOS {
113+ case "darwin" :
114+ otherOS = "linux"
115+ case "linux" :
116+ otherOS = "darwin"
117+ case "windows" :
118+ otherOS = "linux"
119+ default :
120+ otherOS = "windows"
121+ }
106122 result , err := evaluator .Evaluate (map [string ]interface {}{
107- "os" : "linux" ,
123+ "os" : otherOS ,
108124 })
109125 assert .NoError (t , err )
110126 assert .False (t , result )
@@ -147,7 +163,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
147163 })
148164
149165 t .Run ("env_file_contains - key exists in .env file" , func (t * testing.T ) {
150- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("DB_CONNECTION=sqlite\n APP_KEY=base64:value\n " ), 0644 )
166+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("DB_CONNECTION=sqlite\n APP_KEY=base64:value\n " ), 0644 ) )
151167
152168 result , err := evaluator .Evaluate (map [string ]interface {}{
153169 "env_file_contains" : map [string ]interface {}{
@@ -160,7 +176,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
160176 })
161177
162178 t .Run ("env_file_contains - key exists but is empty" , func (t * testing.T ) {
163- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("DB_CONNECTION=\n APP_KEY=base64:value\n " ), 0644 )
179+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("DB_CONNECTION=\n APP_KEY=base64:value\n " ), 0644 ) )
164180
165181 result , err := evaluator .Evaluate (map [string ]interface {}{
166182 "env_file_contains" : map [string ]interface {}{
@@ -173,7 +189,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
173189 })
174190
175191 t .Run ("env_file_contains - key does not exist in .env file" , func (t * testing.T ) {
176- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 )
192+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 ) )
177193
178194 result , err := evaluator .Evaluate (map [string ]interface {}{
179195 "env_file_contains" : map [string ]interface {}{
@@ -197,7 +213,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
197213 })
198214
199215 t .Run ("env_file_contains - key with default .env file" , func (t * testing.T ) {
200- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("DB_CONNECTION=sqlite\n " ), 0644 )
216+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("DB_CONNECTION=sqlite\n " ), 0644 ) )
201217
202218 result , err := evaluator .Evaluate (map [string ]interface {}{
203219 "env_file_contains" : "DB_CONNECTION" ,
@@ -218,7 +234,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
218234 })
219235
220236 t .Run ("env_file_missing - key does not exist" , func (t * testing.T ) {
221- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 )
237+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 ) )
222238
223239 result , err := evaluator .Evaluate (map [string ]interface {}{
224240 "env_file_missing" : map [string ]interface {}{
@@ -231,7 +247,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
231247 })
232248
233249 t .Run ("env_file_missing - key exists but is empty" , func (t * testing.T ) {
234- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=\n " ), 0644 )
250+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=\n " ), 0644 ) )
235251
236252 result , err := evaluator .Evaluate (map [string ]interface {}{
237253 "env_file_missing" : map [string ]interface {}{
@@ -244,7 +260,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
244260 })
245261
246262 t .Run ("env_file_missing - key exists with value" , func (t * testing.T ) {
247- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 )
263+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 ) )
248264
249265 result , err := evaluator .Evaluate (map [string ]interface {}{
250266 "env_file_missing" : map [string ]interface {}{
@@ -257,7 +273,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
257273 })
258274
259275 t .Run ("env_file_missing - key with default .env file" , func (t * testing.T ) {
260- os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 )
276+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , ".env" ), []byte ("APP_KEY=base64:value\n " ), 0644 ) )
261277
262278 result , err := evaluator .Evaluate (map [string ]interface {}{
263279 "env_file_missing" : "APP_KEY" ,
@@ -267,7 +283,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
267283 })
268284
269285 t .Run ("not condition - negates true condition" , func (t * testing.T ) {
270- os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 )
286+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 ) )
271287
272288 result , err := evaluator .Evaluate (map [string ]interface {}{
273289 "not" : map [string ]interface {}{
@@ -289,7 +305,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
289305 })
290306
291307 t .Run ("multiple conditions - all true" , func (t * testing.T ) {
292- os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 )
308+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 ) )
293309
294310 result , err := evaluator .Evaluate (map [string ]interface {}{
295311 "file_exists" : "test.txt" ,
@@ -300,7 +316,7 @@ func TestConditionEvaluator_Evaluate(t *testing.T) {
300316 })
301317
302318 t .Run ("multiple conditions - one false" , func (t * testing.T ) {
303- os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 )
319+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , "test.txt" ), []byte ("test" ), 0644 ) )
304320
305321 result , err := evaluator .Evaluate (map [string ]interface {}{
306322 "file_exists" : "test.txt" ,
@@ -324,15 +340,15 @@ func TestConditionEvaluator_fileHasScript(t *testing.T) {
324340 evaluator := NewConditionEvaluator (ctx )
325341
326342 t .Run ("package.json has script" , func (t * testing.T ) {
327- os .WriteFile (filepath .Join (tmpDir , "package.json" ), []byte (`{"scripts": {"build": "vite build"}}` ), 0644 )
343+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , "package.json" ), []byte (`{"scripts": {"build": "vite build"}}` ), 0644 ) )
328344
329345 result , err := evaluator .fileHasScript ("build" )
330346 require .NoError (t , err )
331347 assert .True (t , result )
332348 })
333349
334350 t .Run ("package.json does not have script" , func (t * testing.T ) {
335- os .WriteFile (filepath .Join (tmpDir , "package.json" ), []byte (`{"scripts": {"test": "jest"}}` ), 0644 )
351+ require . NoError ( t , os .WriteFile (filepath .Join (tmpDir , "package.json" ), []byte (`{"scripts": {"test": "jest"}}` ), 0644 ) )
336352
337353 result , err := evaluator .fileHasScript ("build" )
338354 require .NoError (t , err )
0 commit comments