github.com/databricks/cli@v0.203.0/bundle/config/mutator/select_environment_test.go (about) 1 package mutator_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/databricks/cli/bundle" 8 "github.com/databricks/cli/bundle/config" 9 "github.com/databricks/cli/bundle/config/mutator" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestSelectEnvironment(t *testing.T) { 15 bundle := &bundle.Bundle{ 16 Config: config.Root{ 17 Workspace: config.Workspace{ 18 Host: "foo", 19 }, 20 Environments: map[string]*config.Environment{ 21 "default": { 22 Workspace: &config.Workspace{ 23 Host: "bar", 24 }, 25 }, 26 }, 27 }, 28 } 29 err := mutator.SelectEnvironment("default").Apply(context.Background(), bundle) 30 require.NoError(t, err) 31 assert.Equal(t, "bar", bundle.Config.Workspace.Host) 32 } 33 34 func TestSelectEnvironmentNotFound(t *testing.T) { 35 bundle := &bundle.Bundle{ 36 Config: config.Root{ 37 Environments: map[string]*config.Environment{ 38 "default": {}, 39 }, 40 }, 41 } 42 err := mutator.SelectEnvironment("doesnt-exist").Apply(context.Background(), bundle) 43 require.Error(t, err, "no environments defined") 44 }