2022-11-18 09:57:31 +00:00
|
|
|
package mutator_test
|
|
|
|
|
|
|
|
import (
|
2022-11-28 09:59:43 +00:00
|
|
|
"context"
|
2022-11-18 09:57:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/databricks/cli/bundle/config/mutator"
|
2022-11-18 09:57:31 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSelectEnvironment(t *testing.T) {
|
2022-11-28 09:59:43 +00:00
|
|
|
bundle := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Workspace: config.Workspace{
|
|
|
|
Host: "foo",
|
|
|
|
},
|
|
|
|
Environments: map[string]*config.Environment{
|
|
|
|
"default": {
|
|
|
|
Workspace: &config.Workspace{
|
|
|
|
Host: "bar",
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-05-24 12:45:19 +00:00
|
|
|
err := mutator.SelectEnvironment("default").Apply(context.Background(), bundle)
|
2022-11-18 09:57:31 +00:00
|
|
|
require.NoError(t, err)
|
2022-11-28 09:59:43 +00:00
|
|
|
assert.Equal(t, "bar", bundle.Config.Workspace.Host)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSelectEnvironmentNotFound(t *testing.T) {
|
2022-11-28 09:59:43 +00:00
|
|
|
bundle := &bundle.Bundle{
|
|
|
|
Config: config.Root{
|
|
|
|
Environments: map[string]*config.Environment{
|
|
|
|
"default": {},
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
2023-05-24 12:45:19 +00:00
|
|
|
err := mutator.SelectEnvironment("doesnt-exist").Apply(context.Background(), bundle)
|
2022-11-18 09:57:31 +00:00
|
|
|
require.Error(t, err, "no environments defined")
|
|
|
|
}
|