Skip to content

Commit

Permalink
fix: implement faker record for cloudflare (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
luismayta committed Jul 7, 2024
1 parent 0dbfb00 commit 96f661a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ repos:
- --verbose
- id: hadolint
args:
- --config=.ci/linters/.hadolint.yaml
- --config=.ci/linters/.hadolint.yaml
4 changes: 2 additions & 2 deletions internal/app/external/faker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func Generator() {
_ = fakerTag.AddProvider("userNameFaker", func(v reflect.Value) (interface{}, error) {
return User().Name(), nil
_ = fakerTag.AddProvider("RecordNameFaker", func(v reflect.Value) (interface{}, error) {
return Record().Name(), nil
})
}
34 changes: 34 additions & 0 deletions internal/app/external/faker/record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package faker

import (
"crypto/rand"
"fmt"
"math/big"

"github.com/lithammer/shortuuid/v3"

"github.com/hadenlabs/terraform-cloudflare/internal/errors"
)

type FakeRecord interface {
Name() string // Name server
}

type fakeRecord struct{}

func Record() FakeRecord {
return fakeRecord{}
}

var (
names = []string{"OptimusPrime", "Wheeljack", "Bumblebee"}
)

func (n fakeRecord) Name() string {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(names))))
if err != nil {
panic(errors.New(errors.ErrorUnknown, err.Error()))
}
nameuuid := fmt.Sprintf("%s-%s", names[num.Int64()], shortuuid.New())
return nameuuid
}
15 changes: 15 additions & 0 deletions internal/app/external/faker/record_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package faker

import (
"testing"

"strings"

"github.com/stretchr/testify/assert"
)

func TestFakeRecordName(t *testing.T) {
name := Record().Name()
namePrefix := strings.Split(name, "-")[0]
assert.Contains(t, names, namePrefix, namePrefix)
}
55 changes: 0 additions & 55 deletions internal/app/external/faker/user.go

This file was deleted.

23 changes: 0 additions & 23 deletions internal/app/external/faker/user_test.go

This file was deleted.

0 comments on commit 96f661a

Please sign in to comment.