github.com/Microsoft/fabrikate@v0.0.0-20190420002442-bff75be28d02/cmd/set_test.go (about) 1 package cmd 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestSetValue(t *testing.T) { 11 err := os.Chdir("../test/fixtures/set") 12 assert.Nil(t, err) 13 noNewConfigKeys := false 14 15 // malformed value assignment, should return error 16 err = Set("test", "", []string{"zoo"}, noNewConfigKeys) 17 assert.NotNil(t, err) 18 19 // malformed value assignment, should return error 20 err = Set("test", "", []string{"zoo=zaa=wrong"}, noNewConfigKeys) 21 assert.NotNil(t, err) 22 23 // apply 'faa' as value for 'foo' in component 'test' config 24 err = Set("test", "", []string{"foo=faa"}, noNewConfigKeys) 25 assert.Nil(t, err) 26 27 // apply 'zaa' as value for 'zoo' in subcomponent 'myapp' 'test' config 28 err = Set("test", "myapp", []string{"zoo=zaa"}, noNewConfigKeys) 29 assert.Nil(t, err) 30 31 // create new environment 32 _ = os.Remove("./config/new.yaml") 33 err = Set("new", "myapp", []string{"zoo.zii=zaa"}, noNewConfigKeys) 34 assert.Nil(t, err) 35 36 // update deep config on existing environment 37 err = Set("new", "myapp", []string{"zoo.zii=zbb"}, noNewConfigKeys) 38 assert.Nil(t, err) 39 40 // deep subcomponent config set 41 err = Set("new", "myapp.mysubapp", []string{"foo.bar=zoo"}, noNewConfigKeys) 42 assert.Nil(t, err) 43 44 // set existing value with new noNewConfigKeys switch on 45 noNewConfigKeys = true 46 err = Set("test", "", []string{"foo=faa"}, noNewConfigKeys) 47 assert.Nil(t, err) 48 49 err = Set("test", "", []string{"newfoo=faa"}, noNewConfigKeys) 50 assert.NotNil(t, err) 51 52 err = os.Chdir("../../../cmd") 53 assert.Nil(t, err) 54 }