refactor: change package names

This commit is contained in:
Julian Tölle 2024-05-02 21:42:36 +02:00
parent 62578ad5c5
commit 4b77b81689
24 changed files with 167 additions and 155 deletions

View file

@ -0,0 +1,19 @@
package randomid
import (
"crypto/rand"
"encoding/hex"
"fmt"
)
// From https://gitlab.com/hetznercloud/fleeting-plugin-hetzner/-/blob/0f60204582289c243599f8ca0f5be4822789131d/internal/utils/random.go
// Copyright (c) 2024 Hetzner Cloud GmbH
func Generate() (string, error) {
b := make([]byte, 4)
_, err := rand.Read(b)
if err != nil {
return "", fmt.Errorf("failed to generate random string: %w", err)
}
return hex.EncodeToString(b), nil
}

View file

@ -0,0 +1,18 @@
package randomid
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerateRandomID(t *testing.T) {
found1, err := Generate()
assert.NoError(t, err)
found2, err := Generate()
assert.NoError(t, err)
assert.Len(t, found1, 8)
assert.Len(t, found2, 8)
assert.NotEqual(t, found1, found2)
}