-
Notifications
You must be signed in to change notification settings - Fork 210
/
deployment.go
61 lines (53 loc) · 1.72 KB
/
deployment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package testutil
import (
"crypto/sha256"
"math/rand"
"testing"
dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
)
// sum256Seed provides a consistent sha256 value for initial Deployment.Version
const sum256Seed = "hihi"
// DefaultDeploymentVersion provides consistent sha256 sum for initial Deployment.Version
var DefaultDeploymentVersion = sha256.Sum256([]byte(sum256Seed))
// Deployment generates a dtype.Deployment in state `DeploymentActive`
func Deployment(t testing.TB) dtypes.Deployment {
t.Helper()
return dtypes.Deployment{
DeploymentID: DeploymentID(t),
State: dtypes.DeploymentActive,
Version: DefaultDeploymentVersion[:],
}
}
// DeploymentGroup generates a dtype.DepDeploymentGroup in state `GroupOpen`
// with a set of random required attributes
func DeploymentGroup(t testing.TB, did dtypes.DeploymentID, gseq uint32) dtypes.Group {
t.Helper()
return dtypes.Group{
GroupID: dtypes.MakeGroupID(did, gseq),
State: dtypes.GroupOpen,
GroupSpec: dtypes.GroupSpec{
Name: Name(t, "dgroup"),
Requirements: PlacementRequirements(t),
Resources: Resources(t),
},
}
}
// GroupSpec generator
func GroupSpec(t testing.TB) dtypes.GroupSpec {
t.Helper()
return dtypes.GroupSpec{
Name: Name(t, "dgroup"),
Requirements: PlacementRequirements(t),
Resources: Resources(t),
}
}
// DeploymentGroups returns a set of deployment groups generated by DeploymentGroup
func DeploymentGroups(t testing.TB, did dtypes.DeploymentID, gseq uint32) []dtypes.Group {
t.Helper()
count := rand.Intn(5) + 5 // nolint:gosec
vals := make([]dtypes.Group, 0, count)
for i := 0; i < count; i++ {
vals = append(vals, DeploymentGroup(t, did, gseq+uint32(i)))
}
return vals
}