Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable debugging integration tests in VS Code #2053

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration/assumptions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/bundle/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/alerts/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/auth/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/clusters/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/fs/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/jobs/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/repos/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/secrets/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/storage_credentials/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/sync/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/version/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/cmd/workspace/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
44 changes: 0 additions & 44 deletions integration/internal/acc/debug.go

This file was deleted.

20 changes: 4 additions & 16 deletions integration/internal/acc/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,20 @@ type WorkspaceT struct {
}

func WorkspaceTest(t testutil.TestingT) (context.Context, *WorkspaceT) {
loadDebugEnvIfRunFromIDE(t, "workspace")

t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

w, err := databricks.NewWorkspaceClient()
require.NoError(t, err)

wt := &WorkspaceT{
TestingT: t,

W: w,

ctx: context.Background(),
W: w,
ctx: context.Background(),
}

return wt.ctx, wt
}

// Run the workspace test only on UC workspaces.
func UcWorkspaceTest(t testutil.TestingT) (context.Context, *WorkspaceT) {
loadDebugEnvIfRunFromIDE(t, "workspace")

t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

if os.Getenv("TEST_METASTORE_ID") == "" {
t.Skipf("Skipping on non-UC workspaces")
}
Expand All @@ -57,10 +47,8 @@ func UcWorkspaceTest(t testutil.TestingT) (context.Context, *WorkspaceT) {

wt := &WorkspaceT{
TestingT: t,

W: w,

ctx: context.Background(),
W: w,
ctx: context.Background(),
}

return wt.ctx, wt
Expand Down
48 changes: 46 additions & 2 deletions integration/internal/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
package internal

import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"testing"
)

// Main is the entry point for integration tests.
// Detects if test is run from "debug test" feature in VS Code.
func isInDebug() bool {
ex, _ := os.Executable()
return strings.HasPrefix(path.Base(ex), "__debug_bin")
}

// Loads debug environment from ~/.databricks/debug-env.json.
func loadDebugEnvIfRunFromIDE(key string) error {
if !isInDebug() {
return nil
}
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("cannot find user home: %s", err)
}
raw, err := os.ReadFile(filepath.Join(home, ".databricks/debug-env.json"))
if err != nil {
return fmt.Errorf("cannot load ~/.databricks/debug-env.json: %s", err)
}
var conf map[string]map[string]string
err = json.Unmarshal(raw, &conf)
if err != nil {
return fmt.Errorf("cannot parse ~/.databricks/debug-env.json: %s", err)
}
vars, ok := conf[key]
if !ok {
return fmt.Errorf("%s is not configured in ~/.databricks/debug-env.json", key)
}
for k, v := range vars {
os.Setenv(k, v)
}
return nil
}

// WorkspaceMain is the entry point for integration tests that run against a Databricks workspace.
// We use this for all integration tests defined in this subtree to ensure
// they are not inadvertently executed when calling `go test ./...`.
func Main(m *testing.M) {
func WorkspaceMain(m *testing.M) {
err := loadDebugEnvIfRunFromIDE("workspace")
if err != nil {
fmt.Printf("failed to load debug env: %s\n", err)
return
}

value := os.Getenv("CLOUD_ENV")
if value == "" {
fmt.Println("CLOUD_ENV is not set, skipping integration tests")
Expand Down
4 changes: 2 additions & 2 deletions integration/libs/filer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/libs/git/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/libs/locker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/libs/tags/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
4 changes: 2 additions & 2 deletions integration/python/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
// See [internal.WorkspaceMain] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
internal.WorkspaceMain(m)
}
Loading