mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 08:55:43 +03:00
deps: remove gofakeit (#25073)
This dependency is only used to generate mock `Variables`. The only time the faked values are meaningful would be in the state store and RPC handler tests, where we are always setting the values directly so that we can control unblocking behaviors. Remove most of the random generation and remove the dependency. Closes: https://github.com/hashicorp/nomad/pull/25066
This commit is contained in:
1
go.mod
1
go.mod
@@ -19,7 +19,6 @@ require (
|
||||
github.com/aws/aws-sdk-go-v2/config v1.29.6
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.28
|
||||
github.com/aws/smithy-go v1.22.2
|
||||
github.com/brianvoe/gofakeit/v6 v6.20.1
|
||||
github.com/container-storage-interface/spec v1.10.0
|
||||
github.com/containerd/go-cni v1.1.12
|
||||
github.com/containernetworking/cni v1.2.3
|
||||
|
||||
2
go.sum
2
go.sum
@@ -789,8 +789,6 @@ github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/brianvoe/gofakeit/v6 v6.20.1 h1:8ihJ60OvPnPJ2W6wZR7M+TTeaZ9bml0z6oy4gvyJ/ek=
|
||||
github.com/brianvoe/gofakeit/v6 v6.20.1/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8=
|
||||
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
|
||||
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
|
||||
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
|
||||
|
||||
@@ -7,10 +7,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
@@ -18,7 +16,10 @@ type MockVariables map[string]*structs.VariableDecrypted
|
||||
|
||||
func Variable() *structs.VariableDecrypted {
|
||||
return &structs.VariableDecrypted{
|
||||
VariableMetadata: mockVariableMetadata(),
|
||||
VariableMetadata: structs.VariableMetadata{
|
||||
Namespace: "default",
|
||||
Path: "/example/path",
|
||||
},
|
||||
Items: structs.VariableItems{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
@@ -42,12 +43,7 @@ func Variables(minU, maxU uint8) MockVariables {
|
||||
paths := make(map[string]*structs.VariableDecrypted, vc)
|
||||
for i := 0; i < vc; i++ {
|
||||
nv := Variable()
|
||||
// There is an extremely rare chance of path collision because the mock
|
||||
// variables generate their paths randomly. This check will add
|
||||
// an extra component on conflict to (ideally) disambiguate them.
|
||||
if _, found := paths[nv.Path]; found {
|
||||
nv.Path = nv.Path + "/" + fmt.Sprint(time.Now().UnixNano())
|
||||
}
|
||||
nv.Path = fmt.Sprintf("%s/%d", nv.Path, i)
|
||||
paths[nv.Path] = nv
|
||||
svs[i] = nv
|
||||
}
|
||||
@@ -76,7 +72,10 @@ type MockVariablesEncrypted map[string]*structs.VariableEncrypted
|
||||
|
||||
func VariableEncrypted() *structs.VariableEncrypted {
|
||||
return &structs.VariableEncrypted{
|
||||
VariableMetadata: mockVariableMetadata(),
|
||||
VariableMetadata: structs.VariableMetadata{
|
||||
Namespace: "default",
|
||||
Path: "/example/path",
|
||||
},
|
||||
VariableData: structs.VariableData{
|
||||
KeyID: "foo",
|
||||
Data: []byte("foo"),
|
||||
@@ -129,26 +128,3 @@ func (svs MockVariablesEncrypted) List() []*structs.VariableEncrypted {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func mockVariableMetadata() structs.VariableMetadata {
|
||||
envs := []string{"dev", "test", "prod"}
|
||||
envIdx := rand.Intn(3)
|
||||
env := envs[envIdx]
|
||||
domain := gofakeit.DomainName()
|
||||
|
||||
out := structs.VariableMetadata{
|
||||
Namespace: "default",
|
||||
Path: strings.ReplaceAll(env+"."+domain, ".", "/"),
|
||||
CreateIndex: uint64(rand.Intn(100) + 100),
|
||||
CreateTime: gofakeit.DateRange(time.Now().AddDate(0, -1, 0), time.Now()).UnixNano(),
|
||||
}
|
||||
out.ModifyIndex = out.CreateIndex
|
||||
out.ModifyTime = out.CreateTime
|
||||
|
||||
// Flip a coin to see if we should return a "modified" object
|
||||
if gofakeit.Bool() {
|
||||
out.ModifyTime = gofakeit.DateRange(time.Unix(0, out.CreateTime), time.Now()).UnixNano()
|
||||
out.ModifyIndex = out.CreateIndex + uint64(rand.Intn(100))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -1589,7 +1589,7 @@ func TestVariablesEndpoint_RenewLock(t *testing.T) {
|
||||
state := srv.fsm.State()
|
||||
|
||||
unlockedVar := mock.VariableEncrypted()
|
||||
|
||||
unlockedVar.Path = "/unlocked/var"
|
||||
vsResp := state.VarSet(102, &structs.VarApplyStateRequest{
|
||||
Op: structs.VarOpSet,
|
||||
Var: unlockedVar,
|
||||
@@ -1597,6 +1597,7 @@ func TestVariablesEndpoint_RenewLock(t *testing.T) {
|
||||
must.NoError(t, vsResp.Error)
|
||||
|
||||
lockedVar := mock.VariableEncrypted()
|
||||
lockedVar.Path = "/locked/var"
|
||||
lockedVar.VariableMetadata.Lock = &structs.VariableLock{
|
||||
ID: "theLockID",
|
||||
TTL: 24 * time.Hour,
|
||||
|
||||
Reference in New Issue
Block a user