From be17d549d6297d609658fda37e62ff68e53bd609 Mon Sep 17 00:00:00 2001 From: EspenAlbert Date: Tue, 16 Jul 2024 15:10:18 +0100 Subject: [PATCH] refactor: avoid usage of github.com/go-test/deep (use `reflect.DeepEqual instead`) --- go.mod | 1 - internal/common/conversion/encode_state_test.go | 10 +++++----- .../model_cloud_backup_snapshot_test.go | 6 +++--- .../service/eventtrigger/resource_event_trigger.go | 8 +++----- internal/service/searchindex/model_search_index.go | 5 ++--- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index eb750c90f4..c279876d87 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.22 require ( github.com/andygrunwald/go-jira/v2 v2.0.0-20240116150243-50d59fe116d6 github.com/aws/aws-sdk-go v1.54.17 - github.com/go-test/deep v1.1.1 github.com/hashicorp/go-changelog v0.0.0-20240318095659-4d68c58a6e7f github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-version v1.7.0 diff --git a/internal/common/conversion/encode_state_test.go b/internal/common/conversion/encode_state_test.go index 94628c994f..1b3e75c239 100644 --- a/internal/common/conversion/encode_state_test.go +++ b/internal/common/conversion/encode_state_test.go @@ -1,9 +1,9 @@ package conversion_test import ( + "reflect" "testing" - "github.com/go-test/deep" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" ) @@ -16,8 +16,8 @@ func TestEncodeDecodeID(t *testing.T) { got := conversion.DecodeStateID(conversion.EncodeStateID(expected)) - if diff := deep.Equal(expected, got); diff != nil { - t.Fatalf("Bad testEncodeDecodeID return \n got = %#v\nwant = %#v \ndiff = %#v", got, expected, diff) + if !reflect.DeepEqual(expected, got) { + t.Fatalf("Bad testEncodeDecodeID return \n got = %#v\nwant = %#v", got, expected) } } @@ -28,7 +28,7 @@ func TestDecodeID(t *testing.T) { got := conversion.DecodeStateID(expected) got2 := conversion.DecodeStateID(expected2) - if diff := deep.Equal(got, got2); diff != nil { - t.Fatalf("Bad TestDecodeID return \n got = %#v\nwant = %#v \ndiff = %#v", got, got2, diff) + if !reflect.DeepEqual(got, got2) { + t.Fatalf("Bad TestDecodeID return \n got = %#v\nwant = %#v", got, got2) } } diff --git a/internal/service/cloudbackupsnapshot/model_cloud_backup_snapshot_test.go b/internal/service/cloudbackupsnapshot/model_cloud_backup_snapshot_test.go index 2279919f71..269e98010e 100644 --- a/internal/service/cloudbackupsnapshot/model_cloud_backup_snapshot_test.go +++ b/internal/service/cloudbackupsnapshot/model_cloud_backup_snapshot_test.go @@ -1,9 +1,9 @@ package cloudbackupsnapshot_test import ( + "reflect" "testing" - "github.com/go-test/deep" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshot" "go.mongodb.org/atlas-sdk/v20240530002/admin" ) @@ -20,8 +20,8 @@ func TestSplitSnapshotImportID(t *testing.T) { SnapshotId: "5cf5a45a9ccf6400e60981b7", } - if diff := deep.Equal(expected, got); diff != nil { - t.Errorf("Bad splitSnapshotImportID return \n got = %#v\nwant = %#v \ndiff = %#v", expected, *got, diff) + if !reflect.DeepEqual(expected, got) { + t.Errorf("Bad splitSnapshotImportID return \n got = %#v\nwant = %#v", expected, *got) } if _, err := cloudbackupsnapshot.SplitSnapshotImportID("5cf5a45a9ccf6400e60981b6projectname-environment-mongo-global-cluster5cf5a45a9ccf6400e60981b7"); err == nil { diff --git a/internal/service/eventtrigger/resource_event_trigger.go b/internal/service/eventtrigger/resource_event_trigger.go index 2a91685775..0aa40f2b27 100644 --- a/internal/service/eventtrigger/resource_event_trigger.go +++ b/internal/service/eventtrigger/resource_event_trigger.go @@ -7,9 +7,9 @@ import ( "fmt" "log" "net/http" + "reflect" "strings" - "github.com/go-test/deep" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -118,8 +118,7 @@ func Resource() *schema.Resource { log.Printf("[ERROR] json.Unmarshal %v", err) return false } - if diff := deep.Equal(&j, &j2); diff != nil { - log.Printf("[DEBUG] deep equal not passed: %v", diff) + if !reflect.DeepEqual(&j, &j2) { return false } @@ -140,8 +139,7 @@ func Resource() *schema.Resource { log.Printf("[ERROR] json.Unmarshal %v", err) return false } - if diff := deep.Equal(&j, &j2); diff != nil { - log.Printf("[DEBUG] deep equal not passed: %v", diff) + if !reflect.DeepEqual(&j, &j2) { return false } diff --git a/internal/service/searchindex/model_search_index.go b/internal/service/searchindex/model_search_index.go index 4fcb07b7a8..6b5adfbbb4 100644 --- a/internal/service/searchindex/model_search_index.go +++ b/internal/service/searchindex/model_search_index.go @@ -5,9 +5,9 @@ import ( "context" "encoding/json" "log" + "reflect" "strconv" - "github.com/go-test/deep" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -131,8 +131,7 @@ func diffSuppressJSON(k, old, newStr string, d *schema.ResourceData) bool { if err := json.Unmarshal([]byte(newStr), &j2); err != nil { log.Printf("[ERROR] cannot unmarshal new search index analyzer json %v", err) } - if diff := deep.Equal(&j, &j2); diff != nil { - log.Printf("[DEBUG] deep equal not passed: %v", diff) + if !reflect.DeepEqual(&j, &j2) { return false }