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/apierr"
|
|
|
|
"github.com/databricks/databricks-sdk-go/experimental/mocks"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-11-20 22:12:16 +00:00
|
|
|
func TestResolveMetastore_ResolveSuccess(t *testing.T) {
|
2024-11-20 21:40:43 +00:00
|
|
|
m := mocks.NewMockWorkspaceClient(t)
|
|
|
|
|
|
|
|
api := m.GetMockMetastoresAPI()
|
|
|
|
api.EXPECT().
|
|
|
|
GetByName(mock.Anything, "metastore").
|
|
|
|
Return(&catalog.MetastoreInfo{
|
|
|
|
MetastoreId: "abcd",
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2024-11-20 22:12:16 +00:00
|
|
|
l := resolveMetastore{name: "metastore"}
|
2024-11-20 21:40:43 +00:00
|
|
|
result, err := l.Resolve(ctx, m.WorkspaceClient)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "abcd", result)
|
|
|
|
}
|
|
|
|
|
2024-11-20 22:12:16 +00:00
|
|
|
func TestResolveMetastore_ResolveNotFound(t *testing.T) {
|
2024-11-20 21:40:43 +00:00
|
|
|
m := mocks.NewMockWorkspaceClient(t)
|
|
|
|
|
|
|
|
api := m.GetMockMetastoresAPI()
|
|
|
|
api.EXPECT().
|
|
|
|
GetByName(mock.Anything, "metastore").
|
|
|
|
Return(nil, &apierr.APIError{StatusCode: 404})
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2024-11-20 22:12:16 +00:00
|
|
|
l := resolveMetastore{name: "metastore"}
|
2024-11-20 21:40:43 +00:00
|
|
|
_, err := l.Resolve(ctx, m.WorkspaceClient)
|
|
|
|
require.ErrorIs(t, err, apierr.ErrNotFound)
|
|
|
|
}
|
|
|
|
|
2024-11-20 22:12:16 +00:00
|
|
|
func TestResolveMetastore_String(t *testing.T) {
|
|
|
|
l := resolveMetastore{name: "name"}
|
2024-11-20 21:40:43 +00:00
|
|
|
assert.Equal(t, "metastore: name", l.String())
|
|
|
|
}
|