From feb77686b5b04bb397b4d184459ed36099c182ad Mon Sep 17 00:00:00 2001 From: Anders Rex Date: Thu, 18 Jul 2024 11:51:54 +0300 Subject: [PATCH] Add tests --- .../config/mutator/validate_workspace_host.go | 2 +- .../mutator/validate_workspace_host_test.go | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 bundle/config/mutator/validate_workspace_host_test.go diff --git a/bundle/config/mutator/validate_workspace_host.go b/bundle/config/mutator/validate_workspace_host.go index 3ffb27b9..5450ab96 100644 --- a/bundle/config/mutator/validate_workspace_host.go +++ b/bundle/config/mutator/validate_workspace_host.go @@ -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 diff --git a/bundle/config/mutator/validate_workspace_host_test.go b/bundle/config/mutator/validate_workspace_host_test.go new file mode 100644 index 00000000..718d2dac --- /dev/null +++ b/bundle/config/mutator/validate_workspace_host_test.go @@ -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) +}