github.com/saucelabs/saucectl@v0.175.1/internal/cypress/v1alpha/native_test.go (about) 1 package v1alpha 2 3 import ( 4 "path/filepath" 5 "reflect" 6 "testing" 7 8 "gotest.tools/v3/fs" 9 ) 10 11 func TestConfigFromFile(t *testing.T) { 12 tests := []struct { 13 name string 14 fileContent string 15 want Config 16 wantErr bool 17 }{ 18 { 19 name: "Valid File - Empty", 20 fileContent: `{}`, 21 want: Config{}, 22 wantErr: false, 23 }, 24 { 25 name: "Valid File - Integration folder", 26 fileContent: `{"integrationFolder":"./e2e/integration"}`, 27 want: Config{IntegrationFolder: "./e2e/integration"}, 28 wantErr: false, 29 }, 30 { 31 name: "Invalid File", 32 fileContent: `{"integrationFolder":"./e2e/integration}`, 33 want: Config{}, 34 wantErr: true, 35 }, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 dir := fs.NewDir(t, "cypress-config", fs.WithMode(0755), 40 fs.WithFile("cypress.json", tt.fileContent, fs.WithMode(0644))) 41 defer dir.Remove() 42 43 tt.want.Path = filepath.Join(dir.Path(), "cypress.json") 44 45 got, err := configFromFile(dir.Join("cypress.json")) 46 if (err != nil) != tt.wantErr { 47 t.Errorf("configFromFile() error = %v, wantErr %v", err, tt.wantErr) 48 return 49 } 50 if !reflect.DeepEqual(got, tt.want) { 51 t.Errorf("configFromFile() got = %v, want %v", got, tt.want) 52 } 53 }) 54 } 55 }