Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Jan 31, 2024
1 parent 1d54f44 commit 4aa5fbe
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion vectorsearch/resource_vector_search_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,55 @@ 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) {
qa.ResourceCornerCases(t, ResourceVectorSearchEndpoint())
}

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())
}

0 comments on commit 4aa5fbe

Please sign in to comment.