From 4aa5fbeecedea0d489c2b30f05dab06c89615123 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Wed, 31 Jan 2024 19:46:00 +0100 Subject: [PATCH] Add unit tests --- .../resource_vector_search_endpoint_test.go | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/vectorsearch/resource_vector_search_endpoint_test.go b/vectorsearch/resource_vector_search_endpoint_test.go index 947c2d47e4..e87353ce85 100644 --- a/vectorsearch/resource_vector_search_endpoint_test.go +++ b/vectorsearch/resource_vector_search_endpoint_test.go @@ -3,9 +3,13 @@ package vectorsearch import ( "testing" + "github.com/databricks/databricks-sdk-go/experimental/mocks" "github.com/databricks/terraform-provider-databricks/qa" + "github.com/databricks/databricks-sdk-go/service/vectorsearch" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" ) func TestVectorSearchEndpointCornerCases(t *testing.T) { @@ -13,5 +17,41 @@ func TestVectorSearchEndpointCornerCases(t *testing.T) { } func TestVectorSearchEndpointCreate(t *testing.T) { - assert.Equal(t, 1, 1) + ei := &vectorsearch.EndpointInfo{ + Name: "abc", + EndpointStatus: &vectorsearch.EndpointStatus{State: "ONLINE"}, + Id: "1234-5678", + } + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { + e := w.GetMockVectorSearchEndpointsAPI().EXPECT() + e.CreateEndpointAndWait(mock.Anything, vectorsearch.CreateEndpoint{ + Name: "abc", + EndpointType: "STANDARD", + }, mock.Anything).Return(ei, nil) + e.GetEndpointByEndpointName(mock.Anything, "abc").Return(ei, nil) + }, + Resource: ResourceVectorSearchEndpoint(), + HCL: ` + name = "abc" + endpoint_type = "STANDARD" + `, + Create: true, + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "abc", d.Id()) + assert.Equal(t, "1234-5678", d.Get("endpoint_id")) +} + +func TestResourcePASDelete(t *testing.T) { + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(a *mocks.MockWorkspaceClient) { + a.GetMockVectorSearchEndpointsAPI().EXPECT().DeleteEndpointByEndpointName(mock.Anything, "abc").Return(nil) + }, + Resource: ResourceVectorSearchEndpoint(), + Delete: true, + ID: "abc", + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "abc", d.Id()) }