github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/projectfile/projectfield_test.go (about) 1 package projectfile 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestProjectField(t *testing.T) { 10 tests := []struct { 11 name string 12 projectRaw string 13 run func(p *projectField) 14 want string 15 }{ 16 { 17 "Add Branch", 18 `https://platform.activestate.com/org/project`, 19 func(p *projectField) { p.SetBranch("main") }, 20 "https://platform.activestate.com/org/project?branch=main", 21 }, 22 { 23 "Add Branch, already has commit", 24 `https://platform.activestate.com/org/project`, 25 func(p *projectField) { p.SetBranch("main") }, 26 "https://platform.activestate.com/org/project?branch=main", 27 }, 28 { 29 "Set Namespace", 30 `https://platform.activestate.com/org1/project1`, 31 func(p *projectField) { p.SetNamespace("org2", "project2") }, 32 "https://platform.activestate.com/org2/project2", 33 }, 34 } 35 for _, tt := range tests { 36 t.Run(tt.name, func(t *testing.T) { 37 pf := NewProjectField() 38 err := pf.LoadProject(tt.projectRaw) 39 assert.NoError(t, err, "Loading data failed") 40 41 tt.run(pf) 42 43 assert.Equal(t, tt.want, pf.Marshal()) 44 }) 45 } 46 }