Skip to content

Commit

Permalink
chore: drop the uuid dependency (#773)
Browse files Browse the repository at this point in the history
Following on from commit 965ad7c, it
was observed that it's possible to completely drop the direct dependency on a
uuid generation package, as it's only used for testing. While it remains as
an indirect dependency, we no longer need to manage keeping up to date.
  • Loading branch information
blgm authored Jan 29, 2025
1 parent d4bdb94 commit bf8c2c4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql"
"github.com/cloudfoundry/csb-brokerpak-azure/terraform-provider-csbmssqldbrunfailover/csbmssqldbrunfailover"
"github.com/cloudfoundry/csb-brokerpak-azure/terraform-provider-csbmssqldbrunfailover/testhelpers"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down Expand Up @@ -44,13 +43,13 @@ var _ = Describe("resource_run_failover resource", Ordered, Label("acceptance"),
var err error

config = testhelpers.FailoverConfig{
ResourceGroupName: fmt.Sprintf("resourcegroupname-%s", uuid.NewString()),
ServerName: fmt.Sprintf("servername-%s", uuid.NewString()),
ResourceGroupName: testhelpers.RandomName("resourcegroupname"),
ServerName: testhelpers.RandomName("servername"),
MainLocation: "eastus",
PartnerServerLocation: "eastus2",
PartnerServerName: fmt.Sprintf("partnerservername-%s", uuid.NewString()),
PartnerServerName: testhelpers.RandomName("partnerservername"),
SubscriptionID: azureSubscriptionID,
FailoverGroupName: fmt.Sprintf("failovergroupname-%s", uuid.NewString()),
FailoverGroupName: testhelpers.RandomName("failovergroupname"),
}

failoverData, err = testhelpers.CreateFailoverGroup(config)
Expand Down
2 changes: 1 addition & 1 deletion providers/terraform-provider-csbmssqldbrunfailover/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql v1.2.0
github.com/google/uuid v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
Expand All @@ -27,6 +26,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package testhelpers

import (
"context"
"fmt"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql"
"github.com/google/uuid"
)

type FailoverData struct {
Expand Down Expand Up @@ -92,8 +90,8 @@ func createServer(ctx context.Context, cred azcore.TokenCredential, resourceGrou
armsql.Server{
Location: to.Ptr(location),
Properties: &armsql.ServerProperties{
AdministratorLogin: to.Ptr(fmt.Sprintf("dummylogin-%s", uuid.NewString())),
AdministratorLoginPassword: to.Ptr(fmt.Sprintf("dummyPassword-%s", uuid.NewString())),
AdministratorLogin: to.Ptr(RandomName("dummylogin")),
AdministratorLoginPassword: to.Ptr(RandomName("dummyPassword")),
},
},
nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package testhelpers

import (
"crypto/rand"
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func RandomName(prefix string) string {
GinkgoHelper()

return fmt.Sprintf("%s-%s", prefix, RandomHex())
}

func RandomHex() string {
GinkgoHelper()

const length = 20
buf := make([]byte, length/2)
_, err := rand.Read(buf)
Expect(err).NotTo(HaveOccurred())
return fmt.Sprintf("%x", buf)
}

0 comments on commit bf8c2c4

Please sign in to comment.