mirror of https://github.com/databricks/cli.git
Clean up TestMain from integration tests to fix caching (#2090)
## Changes - Remove TestMain from integration tests and related checks. - This fixes "go test" caching for integration tests. The test_main.go files were added in https://github.com/databricks/cli/pull/2009 to make sure integration tests are not run as part of go test ./.... We recommend running make test to run tests, which includes the packages to test (and excludes integration). ## Tests To test that caching works I ran a test twice: ``` + CLOUD_ENV=aws + go test --timeout 3h -v -run TestDefaultPython/3.9 ./integration/bundle/ … PASS ok github.com/databricks/cli/integration/bundle (cached) ```
This commit is contained in:
parent
02c7df39f6
commit
8fd793b605
|
@ -1,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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,13 +0,0 @@
|
|||
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)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
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)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package repos_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,13 +0,0 @@
|
|||
package secrets_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,13 +0,0 @@
|
|||
package storage_credentials_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,13 +0,0 @@
|
|||
package sync_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,13 +0,0 @@
|
|||
package version_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,13 +0,0 @@
|
|||
package workspace_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,116 +0,0 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type packageInfo struct {
|
||||
Name string
|
||||
Files []string
|
||||
}
|
||||
|
||||
func enumeratePackages(t *testing.T) map[string]packageInfo {
|
||||
pkgmap := make(map[string]packageInfo)
|
||||
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Skip files.
|
||||
if !info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip the root directory and the "internal" directory.
|
||||
if path == "." || strings.HasPrefix(path, "internal") {
|
||||
return nil
|
||||
}
|
||||
|
||||
fset := token.NewFileSet()
|
||||
pkgs, err := parser.ParseDir(fset, path, nil, parser.ParseComments)
|
||||
require.NoError(t, err)
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Expect one package per directory.
|
||||
require.Len(t, pkgs, 1, "Directory %s contains more than one package", path)
|
||||
v := maps.Values(pkgs)[0]
|
||||
|
||||
// Record the package.
|
||||
pkgmap[path] = packageInfo{
|
||||
Name: v.Name,
|
||||
Files: maps.Keys(v.Files),
|
||||
}
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return pkgmap
|
||||
}
|
||||
|
||||
// TestEnforcePackageNames checks that all integration test package names use the "_test" suffix.
|
||||
// We enforce this package name to avoid package name aliasing.
|
||||
func TestEnforcePackageNames(t *testing.T) {
|
||||
pkgmap := enumeratePackages(t)
|
||||
for _, pkg := range pkgmap {
|
||||
assert.True(t, strings.HasSuffix(pkg.Name, "_test"), "Package name %s does not end with _test", pkg.Name)
|
||||
}
|
||||
}
|
||||
|
||||
var mainTestTemplate = template.Must(template.New("main_test").Parse(
|
||||
`package {{.Name}}
|
||||
|
||||
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)
|
||||
}
|
||||
`))
|
||||
|
||||
func TestEnforceMainTest(t *testing.T) {
|
||||
pkgmap := enumeratePackages(t)
|
||||
for dir, pkg := range pkgmap {
|
||||
found := false
|
||||
for _, file := range pkg.Files {
|
||||
if filepath.Base(file) == "main_test.go" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Expect a "main_test.go" file in each package.
|
||||
assert.True(t, found, "Directory %s does not contain a main_test.go file", dir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteMainTest(t *testing.T) {
|
||||
t.Skip("Uncomment to write main_test.go files")
|
||||
|
||||
pkgmap := enumeratePackages(t)
|
||||
for dir, pkg := range pkgmap {
|
||||
// Write a "main_test.go" file to the package.
|
||||
// This file is required to run the integration tests.
|
||||
f, err := os.Create(filepath.Join(dir, "main_test.go"))
|
||||
require.NoError(t, err)
|
||||
defer f.Close()
|
||||
err = mainTestTemplate.Execute(f, pkg)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/databricks/cli/integration/internal/acc"
|
||||
)
|
||||
|
||||
// Main is the entry point for integration tests.
|
||||
// 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) {
|
||||
value := os.Getenv("CLOUD_ENV")
|
||||
if value == "" && !acc.IsInDebug() {
|
||||
fmt.Println("CLOUD_ENV is not set, skipping integration tests")
|
||||
return
|
||||
}
|
||||
|
||||
m.Run()
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package filer_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,13 +0,0 @@
|
|||
package git_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,13 +0,0 @@
|
|||
package locker_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,13 +0,0 @@
|
|||
package tags_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,13 +0,0 @@
|
|||
package python_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)
|
||||
}
|
Loading…
Reference in New Issue