mirror of https://github.com/databricks/cli.git
Move integration tests to `integration` package (#2009)
## Changes Objectives: * A dedicated directory for integration tests * It is not picked up by `go test ./...` * No need for a `TestAcc` test name prefix * More granular packages to improve test selection (future) 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 the `integration` package. ## Tests Integration tests pass. The total run time regresses by about 10%. A follow-up change that increases the degree of test parallelism will address this.
This commit is contained in:
parent
61b0c59137
commit
c958702097
2
Makefile
2
Makefile
|
@ -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
|
||||
|
|
|
@ -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
|
||||
```
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package assumptions_test
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"os"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"os"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"os"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"testing"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"testing"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package bundle
|
||||
package bundle_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package alerts_test
|
||||
|
||||
import (
|
||||
"testing"
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package auth_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package clusters_test
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -0,0 +1,13 @@
|
|||
package fs_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)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package internal
|
||||
package jobs_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -18,7 +18,7 @@ func TestAccCreateJob(t *testing.T) {
|
|||
if env != "azure" {
|
||||
t.Skipf("Not running test on cloud %s", env)
|
||||
}
|
||||
stdout, stderr := testcli.RequireSuccessfulRun(t, "jobs", "create", "--json", "@testjsons/create_job_without_workers.json", "--log-level=debug")
|
||||
stdout, stderr := testcli.RequireSuccessfulRun(t, "jobs", "create", "--json", "@testdata/create_job_without_workers.json", "--log-level=debug")
|
||||
assert.Empty(t, stderr.String())
|
||||
var output map[string]int
|
||||
err := json.Unmarshal(stdout.Bytes(), &output)
|
|
@ -0,0 +1,13 @@
|
|||
package jobs_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)
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package cmd_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)
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue