github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/projectfile/projectfile_darwin_test.go (about) 1 package projectfile 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/ActiveState/cli/internal/environment" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestYamlMerge(t *testing.T) { 12 rootpath, err := environment.GetRootPath() 13 if err != nil { 14 t.Fatal(err) 15 } 16 17 project, err := Parse(filepath.Join(rootpath, "pkg", "projectfile", "testdata", "activestate.yaml")) 18 assert.NoError(t, err, "Should not throw an error") 19 20 assert.Equal(t, "dev", project.Environments) // should be overridden 21 22 debugConstantsSeen := 0 23 macOSConstantSeen := true 24 assert.True(t, len(project.Constants) > 2) // these constants should not override the others 25 for _, constant := range project.Constants { 26 switch constant.Name { 27 case "DEBUG": 28 // We are merging with mergo's WithAppendSlice, so there will be two variables with this name. 29 // However, we expect the one from activestate.macos.yaml to show up first. 30 if debugConstantsSeen == 0 { 31 assert.Equal(t, "false", constant.Value) // from activestate.macos.yaml 32 } else { 33 assert.Equal(t, "true", constant.Value) // from activestate.yaml 34 } 35 debugConstantsSeen++ 36 case "macOS": 37 assert.Equal(t, "true", constant.Value) // should be added 38 macOSConstantSeen = true 39 } 40 } 41 assert.Equal(t, 2, debugConstantsSeen) 42 assert.True(t, macOSConstantSeen) 43 }