Skip to content

Commit

Permalink
refactor: use randutil from hcloud-go (#965)
Browse files Browse the repository at this point in the history
This PR uses the new feature from
hetznercloud/hcloud-go#580
  • Loading branch information
phm07 authored Jan 22, 2025
1 parent 6797c80 commit 3bd76c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
3 changes: 2 additions & 1 deletion test/e2e/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/kit/randutil"
)

const fingerprintRegex = `[0-9A-F]{2}(:[0-9A-F]{2}){31}`
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestCertificate(t *testing.T) {
}

// random subdomain
certDomain = fmt.Sprintf("%s.%s", randomHex(4), certDomain)
certDomain = fmt.Sprintf("%s.%s", randutil.GenerateID(), certDomain)

certName := withSuffix("test-certificate-managed")
certID, err := createCertificate(t, certName, hcloud.CertificateTypeManaged, "--type", "managed", "--domain", certDomain)
Expand Down
14 changes: 2 additions & 12 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package e2e

import (
"bytes"
"crypto/rand"
"encoding/hex"
"fmt"
"os"
"testing"
Expand All @@ -16,6 +14,7 @@ import (
"github.com/hetznercloud/cli/internal/state"
"github.com/hetznercloud/cli/internal/state/config"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/kit/randutil"
)

var client = hcloud.NewClient(hcloud.WithToken(os.Getenv("HCLOUD_TOKEN")))
Expand Down Expand Up @@ -55,15 +54,6 @@ func runCommand(t *testing.T, args ...string) (string, error) {
return buf.String(), err
}

func randomHex(n int) string {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return hex.EncodeToString(b)
}

func withSuffix(s string) string {
return fmt.Sprintf("%s-%s", s, randomHex(4))
return fmt.Sprintf("%s-%s", s, randutil.GenerateID())
}

0 comments on commit 3bd76c4

Please sign in to comment.