Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ vendor:
@go mod vendor

integration:
gotestsum --format github-actions --rerun-fails --jsonfile output.json --packages "./internal/..." -- -run "TestAcc.*" -parallel 4 -timeout=2h
gotestsum --format github-actions --rerun-fails --jsonfile output.json --packages "./integration/..." -- -parallel 4 -timeout=2h

.PHONY: fmt lint lintcheck test testonly coverage build snapshot vendor integration
37 changes: 37 additions & 0 deletions integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Integration tests

This directory contains integration tests for the project.

The tree structure generally mirrors the source code tree structure.

Requirements for new files in this directory:
* Every package **must** be named after its directory with `_test` appended
* Requiring a different package name for integration tests avoids aliasing with the main package.
* Every integration test package **must** include a `main_test.go` file.

These requirements are enforced by a unit test in this directory.

## Running integration tests

Integration tests require the following environment variables:
* `CLOUD_ENV` - set to the cloud environment to use (e.g. `aws`, `azure`, `gcp`)
* `DATABRICKS_HOST` - set to the Databricks workspace to use
* `DATABRICKS_TOKEN` - set to the Databricks token to use

Optional environment variables:
* `TEST_DEFAULT_WAREHOUSE_ID` - set to the default warehouse ID to use
* `TEST_METASTORE_ID` - set to the metastore ID to use
* `TEST_INSTANCE_POOL_ID` - set to the instance pool ID to use
* `TEST_BRICKS_CLUSTER_ID` - set to the cluster ID to use

To run all integration tests, use the following command:

```bash
go test ./integration/...
```

Alternatively:

```bash
make integration
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package assumptions_test

import (
"encoding/base64"
Expand Down
13 changes: 13 additions & 0 deletions integration/assumptions/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package assumptions_test

import (
"testing"

"github.com/databricks/cli/integration/internal"
)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pietern we might want to re-think this - it turns out having TestMain disables go test's built-in caching, which could be useful in speeding up test runs both locally and on CI.

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"bytes"
Expand Down
9 changes: 5 additions & 4 deletions internal/init_test.go → integration/bundle/init_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package bundle_test

import (
"context"
Expand Down Expand Up @@ -67,8 +67,8 @@ func TestAccBundleInitOnMlopsStacks(t *testing.T) {
testcli.RequireSuccessfulRun(t, "bundle", "init", "mlops-stacks", "--output-dir", tmpDir2, "--config-file", filepath.Join(tmpDir1, "config.json"))

// Assert that the README.md file was created
assert.FileExists(t, filepath.Join(tmpDir2, "repo_name", projectName, "README.md"))
assertLocalFileContents(t, filepath.Join(tmpDir2, "repo_name", projectName, "README.md"), fmt.Sprintf("# %s", projectName))
contents := testutil.ReadFile(t, filepath.Join(tmpDir2, "repo_name", projectName, "README.md"))
assert.Contains(t, contents, fmt.Sprintf("# %s", projectName))

// Validate the stack
testutil.Chdir(t, filepath.Join(tmpDir2, "repo_name", projectName))
Expand Down Expand Up @@ -163,6 +163,7 @@ func TestAccBundleInitHelpers(t *testing.T) {
testcli.RequireSuccessfulRun(t, "bundle", "init", tmpDir, "--output-dir", tmpDir2)

// Assert that the helper function was correctly computed.
assertLocalFileContents(t, filepath.Join(tmpDir2, "foo.txt"), test.expected)
contents := testutil.ReadFile(t, filepath.Join(tmpDir2, "foo.txt"))
assert.Contains(t, contents, test.expected)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
13 changes: 13 additions & 0 deletions integration/bundle/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package bundle_test

import (
"testing"

"github.com/databricks/cli/integration/internal"
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundle
package bundle_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package alerts_test

import (
"testing"
Expand Down
13 changes: 13 additions & 0 deletions integration/cmd/alerts/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package alerts_test

import (
"testing"

"github.com/databricks/cli/integration/internal"
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
}
2 changes: 1 addition & 1 deletion internal/api_test.go → integration/cmd/api/api_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package api_test

import (
"encoding/json"
Expand Down
13 changes: 13 additions & 0 deletions integration/cmd/api/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package api_test

import (
"testing"

"github.com/databricks/cli/integration/internal"
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package auth_test

import (
"context"
Expand All @@ -14,6 +14,8 @@ import (
func TestAuthDescribeSuccess(t *testing.T) {
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

t.Skipf("Skipping because of https://github.com/databricks/cli/issues/2010")

stdout, _ := testcli.RequireSuccessfulRun(t, "auth", "describe")
outStr := stdout.String()

Expand All @@ -35,6 +37,8 @@ func TestAuthDescribeSuccess(t *testing.T) {
func TestAuthDescribeFailure(t *testing.T) {
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

t.Skipf("Skipping because of https://github.com/databricks/cli/issues/2010")

stdout, _ := testcli.RequireSuccessfulRun(t, "auth", "describe", "--profile", "nonexistent")
outStr := stdout.String()

Expand Down
13 changes: 13 additions & 0 deletions integration/cmd/auth/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package auth_test

import (
"testing"

"github.com/databricks/cli/integration/internal"
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package clusters_test

import (
"fmt"
Expand Down
13 changes: 13 additions & 0 deletions integration/cmd/clusters/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package clusters_test

import (
"testing"

"github.com/databricks/cli/integration/internal"
)

// TestMain is the entrypoint executed by the test runner.
// See [internal.Main] for prerequisites for running integration tests.
func TestMain(m *testing.M) {
internal.Main(m)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package fs_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package fs_test

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion internal/fs_cp_test.go → integration/cmd/fs/cp_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package fs_test

import (
"context"
Expand Down
46 changes: 46 additions & 0 deletions integration/cmd/fs/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package fs_test

import (
"os"
"path"
"path/filepath"

"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"

"github.com/databricks/cli/libs/filer"
"github.com/stretchr/testify/require"
)

func setupLocalFiler(t testutil.TestingT) (filer.Filer, string) {
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

tmp := t.TempDir()
f, err := filer.NewLocalClient(tmp)
require.NoError(t, err)

return f, path.Join(filepath.ToSlash(tmp))
}

func setupDbfsFiler(t testutil.TestingT) (filer.Filer, string) {
_, wt := acc.WorkspaceTest(t)

tmpdir := acc.TemporaryDbfsDir(wt)
f, err := filer.NewDbfsClient(wt.W, tmpdir)
require.NoError(t, err)
return f, path.Join("dbfs:/", tmpdir)
}

func setupUcVolumesFiler(t testutil.TestingT) (filer.Filer, string) {
_, wt := acc.WorkspaceTest(t)

if os.Getenv("TEST_METASTORE_ID") == "" {
t.Skip("Skipping tests that require a UC Volume when metastore id is not set.")
}

tmpdir := acc.TemporaryVolume(wt)
f, err := filer.NewFilesClient(wt.W, tmpdir)
require.NoError(t, err)

return f, path.Join("dbfs:/", tmpdir)
}
2 changes: 1 addition & 1 deletion internal/fs_ls_test.go → integration/cmd/fs/ls_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package fs_test

import (
"context"
Expand Down
Loading
Loading