Skip to content

Commit

Permalink
endpoint check
Browse files Browse the repository at this point in the history
  • Loading branch information
RaynorChavez committed Feb 26, 2025
1 parent b39433f commit 8d0e2d5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ linters:
- nilerr
- predeclared
- staticcheck
- usetesting
- unconvert
- unparam
- unused
Expand Down
52 changes: 50 additions & 2 deletions internal/provider/indices_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@ package provider
import (
"fmt"
"regexp"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

// Helper function to check that the endpoint is valid
func testAccCheckEndpointIsValid(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("Not found: %s", resourceName)
}

// Check that marqo_endpoint is set and has a valid format
endpoint := rs.Primary.Attributes["marqo_endpoint"]
if endpoint == "" {
return fmt.Errorf("marqo_endpoint is empty after import")
}

// Verify it's a valid URL format
if !strings.HasPrefix(endpoint, "https://") {
return fmt.Errorf("marqo_endpoint does not have expected format: %s", endpoint)
}

fmt.Printf("Found valid endpoint: %s\n", endpoint)
return nil
}
}

func TestAccResourceCustomModelIndex(t *testing.T) {
t.Parallel() // Enable parallel testing
unstructured_custom_model_index_name := fmt.Sprintf("donotdelete_unstr_resrc_%s", randomString(6))
Expand Down Expand Up @@ -50,10 +75,13 @@ func TestAccResourceCustomModelIndex(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
ImportStateId: unstructured_custom_model_index_name,
// Don't verify these fields as they might be computed or have different representations
ImportStateVerifyIgnore: []string{
"timeouts",
"marqo_endpoint",
},
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
// Delete testing automatically occurs in TestCase
},
Expand Down Expand Up @@ -121,7 +149,11 @@ func TestAccResourceLangBindIndex(t *testing.T) {
// Don't verify these fields as they might be computed or have different representations
ImportStateVerifyIgnore: []string{
"timeouts",
"marqo_endpoint",
},
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
// Update and Read testing
{
Expand Down Expand Up @@ -192,7 +224,11 @@ func TestAccResourceStructuredIndex(t *testing.T) {
// Don't verify these fields as they might be computed or have different representations
ImportStateVerifyIgnore: []string{
"timeouts",
"marqo_endpoint",
},
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
// Check for no changes on re-apply
{
Expand Down Expand Up @@ -252,7 +288,11 @@ func TestAccResourceMinimalIndex(t *testing.T) {
// Don't verify these fields as they might be computed or have different representations
ImportStateVerifyIgnore: []string{
"timeouts",
"marqo_endpoint",
},
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
// Update testing
{
Expand Down Expand Up @@ -345,6 +385,7 @@ func TestAccResourceImportIndex(t *testing.T) {
ImportStateId: import_index_name,
ImportStateVerifyIgnore: []string{
"timeouts",
"marqo_endpoint",
},
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
Expand All @@ -356,6 +397,7 @@ func TestAccResourceImportIndex(t *testing.T) {
resource.TestCheckResourceAttr("marqo_index.test", "settings.model", "open_clip/ViT-L-14/laion2b_s32b_b82k"),
resource.TestCheckResourceAttr("marqo_index.test", "settings.inference_type", "marqo.CPU.large"),
resource.TestCheckResourceAttr("marqo_index.test", "settings.number_of_inferences", "1"),
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
// Verify that we can update the imported resource
Expand Down Expand Up @@ -415,7 +457,8 @@ func TestAccResourceImportStructuredIndex(t *testing.T) {
ImportStateId: import_structured_index_name,
ImportStateVerifyIgnore: []string{
"timeouts",
"settings.all_fields", // all_fields might have different representation in API vs config
"marqo_endpoint",
"settings.all_fields",
},
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
Expand All @@ -426,6 +469,7 @@ func TestAccResourceImportStructuredIndex(t *testing.T) {
resource.TestCheckResourceAttr("marqo_index.test", "settings.type", "structured"),
resource.TestCheckResourceAttr("marqo_index.test", "settings.model", "open_clip/ViT-L-14/laion2b_s32b_b82k"),
resource.TestCheckResourceAttr("marqo_index.test", "settings.inference_type", "marqo.CPU.small"),
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
},
Expand Down Expand Up @@ -889,7 +933,11 @@ func TestAccResourceMaximalIndex(t *testing.T) {
ImportStateId: maximal_index_name,
ImportStateVerifyIgnore: []string{
"timeouts",
"marqo_endpoint",
},
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpointIsValid("marqo_index.test"),
),
},
// Update testing
{
Expand Down

0 comments on commit 8d0e2d5

Please sign in to comment.