mirror of https://github.com/databricks/cli.git
Remove global variable from clusters integration test (#1972)
## Changes I saw this test fail on rerun because the global wasn't set. Fix by removing the global and using a different approach to acquire a valid cluster ID. ## Tests Integration tests.
This commit is contained in:
parent
1b2be1b2cb
commit
e9fa7b7c0e
|
@ -5,11 +5,13 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/databricks/cli/internal/acc"
|
||||||
|
"github.com/databricks/databricks-sdk-go/listing"
|
||||||
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var clusterId string
|
|
||||||
|
|
||||||
func TestAccClustersList(t *testing.T) {
|
func TestAccClustersList(t *testing.T) {
|
||||||
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
||||||
|
|
||||||
|
@ -21,13 +23,14 @@ func TestAccClustersList(t *testing.T) {
|
||||||
assert.Equal(t, "", stderr.String())
|
assert.Equal(t, "", stderr.String())
|
||||||
|
|
||||||
idRegExp := regexp.MustCompile(`[0-9]{4}\-[0-9]{6}-[a-z0-9]{8}`)
|
idRegExp := regexp.MustCompile(`[0-9]{4}\-[0-9]{6}-[a-z0-9]{8}`)
|
||||||
clusterId = idRegExp.FindString(outStr)
|
clusterId := idRegExp.FindString(outStr)
|
||||||
assert.NotEmpty(t, clusterId)
|
assert.NotEmpty(t, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccClustersGet(t *testing.T) {
|
func TestAccClustersGet(t *testing.T) {
|
||||||
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
||||||
|
|
||||||
|
clusterId := findValidClusterID(t)
|
||||||
stdout, stderr := RequireSuccessfulRun(t, "clusters", "get", clusterId)
|
stdout, stderr := RequireSuccessfulRun(t, "clusters", "get", clusterId)
|
||||||
outStr := stdout.String()
|
outStr := stdout.String()
|
||||||
assert.Contains(t, outStr, fmt.Sprintf(`"cluster_id":"%s"`, clusterId))
|
assert.Contains(t, outStr, fmt.Sprintf(`"cluster_id":"%s"`, clusterId))
|
||||||
|
@ -38,3 +41,22 @@ func TestClusterCreateErrorWhenNoArguments(t *testing.T) {
|
||||||
_, _, err := RequireErrorRun(t, "clusters", "create")
|
_, _, err := RequireErrorRun(t, "clusters", "create")
|
||||||
assert.Contains(t, err.Error(), "accepts 1 arg(s), received 0")
|
assert.Contains(t, err.Error(), "accepts 1 arg(s), received 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// findValidClusterID lists clusters in the workspace to find a valid cluster ID.
|
||||||
|
func findValidClusterID(t *testing.T) string {
|
||||||
|
ctx, wt := acc.WorkspaceTest(t)
|
||||||
|
it := wt.W.Clusters.List(ctx, compute.ListClustersRequest{
|
||||||
|
FilterBy: &compute.ListClustersFilterBy{
|
||||||
|
ClusterSources: []compute.ClusterSource{
|
||||||
|
compute.ClusterSourceApi,
|
||||||
|
compute.ClusterSourceUi,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
clusterIDs, err := listing.ToSliceN(ctx, it, 1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, clusterIDs, 1)
|
||||||
|
|
||||||
|
return clusterIDs[0].ClusterId
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue