2024-11-20 21:40:33 +00:00
|
|
|
package variable
|
|
|
|
|
2024-11-20 21:40:43 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/databricks-sdk-go/experimental/mocks"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-11-20 22:12:16 +00:00
|
|
|
func TestResolveCluster_ResolveSuccess(t *testing.T) {
|
2024-11-20 21:40:43 +00:00
|
|
|
m := mocks.NewMockWorkspaceClient(t)
|
|
|
|
|
|
|
|
api := m.GetMockClustersAPI()
|
|
|
|
api.EXPECT().
|
|
|
|
ListAll(mock.Anything, mock.Anything).
|
|
|
|
Return([]compute.ClusterDetails{
|
|
|
|
{ClusterId: "1234", ClusterName: "cluster1"},
|
|
|
|
{ClusterId: "2345", ClusterName: "cluster2"},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2024-11-20 22:12:16 +00:00
|
|
|
l := resolveCluster{name: "cluster2"}
|
2024-11-20 21:40:43 +00:00
|
|
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "2345", result)
|
|
|
|
}
|
|
|
|
|
2024-11-20 22:12:16 +00:00
|
|
|
func TestResolveCluster_ResolveNotFound(t *testing.T) {
|
2024-11-20 21:40:43 +00:00
|
|
|
m := mocks.NewMockWorkspaceClient(t)
|
|
|
|
|
|
|
|
api := m.GetMockClustersAPI()
|
|
|
|
api.EXPECT().
|
|
|
|
ListAll(mock.Anything, mock.Anything).
|
|
|
|
Return([]compute.ClusterDetails{}, nil)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2024-11-20 22:12:16 +00:00
|
|
|
l := resolveCluster{name: "cluster"}
|
2024-11-20 21:40:43 +00:00
|
|
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
|
|
|
require.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "cluster named 'cluster' does not exist")
|
|
|
|
}
|
|
|
|
|
2024-11-20 22:12:16 +00:00
|
|
|
func TestResolveCluster_String(t *testing.T) {
|
|
|
|
l := resolveCluster{name: "name"}
|
2024-11-20 21:40:43 +00:00
|
|
|
assert.Equal(t, "cluster: name", l.String())
|
|
|
|
}
|