Add tests

This commit is contained in:
Anders Rex 2024-07-18 11:51:54 +03:00
parent 153510bfbf
commit feb77686b5
No known key found for this signature in database
GPG Key ID: 06A88681C237F740
2 changed files with 44 additions and 1 deletions

View File

@ -23,7 +23,7 @@ func (m *validateWorkspaceHost) Apply(ctx context.Context, b *bundle.Bundle) dia
target_host := b.Config.Workspace.Host
if env_host != "" && target_host != "" && env_host != target_host {
return diag.Errorf("Target host and DATABRICKS_HOST environment variable mismatch")
return diag.Errorf("target host and DATABRICKS_HOST environment variable mismatch")
}
return nil

View File

@ -0,0 +1,43 @@
package mutator
import (
"context"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/env"
"github.com/stretchr/testify/assert"
)
func TestValidateValidateWorkspaceHost(t *testing.T) {
host := "https://host.databricks.com"
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
Host: host,
},
},
}
t.Setenv(env.HostVariable, host)
m := ValidateWorkspaceHost()
diags := bundle.Apply(context.Background(), b, m)
assert.NoError(t, diags.Error())
}
func TestValidateValidateWorkspaceHostMismatch(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Workspace: config.Workspace{
Host: "https://target-host.databricks.com",
},
},
}
t.Setenv(env.HostVariable, "https://env-host.databricks.com")
m := ValidateWorkspaceHost()
diags := bundle.Apply(context.Background(), b, m)
expectedError := "target host and DATABRICKS_HOST environment variable mismatch"
assert.EqualError(t, diags.Error(), expectedError)
}