Skip to content

Commit d01e215

Browse files
committed
fixes
1 parent aa817a8 commit d01e215

6 files changed

Lines changed: 40 additions & 7 deletions

File tree

v1/bytes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func (b Bytes) GreaterThan(other Bytes) bool {
137137
return b.byteCount.Cmp(other.byteCount) > 0
138138
}
139139

140+
// Equal returns true if the Bytes is equal to the other Bytes
140141
func (b Bytes) Equal(other Bytes) bool {
141142
return b.byteCount.Cmp(other.byteCount) == 0
142143
}

v1/bytes_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,33 @@ func TestBytesByteCountInUnitInt64(t *testing.T) {
375375
})
376376
}
377377
}
378+
379+
func TestBytesByteCountInUnitInt32(t *testing.T) {
380+
tests := []struct {
381+
name string
382+
bytes Bytes
383+
unit BytesUnit
384+
want int32
385+
wantErr error
386+
}{
387+
{name: "2048 MiB -> GiB", bytes: NewBytes(2048, Mebibyte), unit: Gibibyte, want: 2, wantErr: nil},
388+
{name: "2048 EiB -> B", bytes: NewBytes(2048, Exbibyte), unit: Byte, want: 0, wantErr: ErrBytesNotAnInt64},
389+
{name: "2048 EiB -> KB", bytes: NewBytes(2048, Exbibyte), unit: Kilobyte, want: 0, wantErr: ErrBytesNotAnInt32},
390+
}
391+
for _, test := range tests {
392+
t.Run(test.name, func(t *testing.T) {
393+
got, err := test.bytes.ByteCountInUnitInt32(test.unit)
394+
if err != nil {
395+
if test.wantErr != nil {
396+
if !errors.Is(err, test.wantErr) {
397+
t.Errorf("Bytes.ByteCountInUnitInt32() = %v, want %v", err, test.wantErr)
398+
}
399+
} else {
400+
t.Errorf("Bytes.ByteCountInUnitInt32() = %v, want %v", err, test.wantErr)
401+
}
402+
} else if got != test.want {
403+
t.Errorf("Bytes.ByteCountInUnitInt32() = %v, want %v", got, test.want)
404+
}
405+
})
406+
}
407+
}

v1/kubernetes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func TestClusterUnmarshalJSON(t *testing.T) { //nolint:gocyclo,funlen // test ok
209209
if cluster.nodeGroups[0].instanceType != "test-instanceType" {
210210
t.Fatalf("Cluster NodeGroup InstanceType = %s, want %s", cluster.nodeGroups[0].instanceType, "test-instanceType")
211211
}
212-
if cluster.nodeGroups[0].diskSize != NewBytes(10, Gibibyte) {
212+
if !cluster.nodeGroups[0].diskSize.Equal(NewBytes(10, Gibibyte)) {
213213
t.Fatalf("Cluster NodeGroup DiskSize = %s, want %s", cluster.nodeGroups[0].diskSize, "10 GiB")
214214
}
215215
if len(cluster.nodeGroups[0].tags) != 1 {

v1/kubernetes_validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func ValidateCreateKubernetesNodeGroup(ctx context.Context, client CloudMaintain
8484
if nodeGroup.GetInstanceType() != attrs.InstanceType {
8585
return nil, fmt.Errorf("node group instanceType does not match create args: '%s' != '%s'", nodeGroup.GetInstanceType(), attrs.InstanceType)
8686
}
87-
if nodeGroup.GetDiskSize() != attrs.DiskSize {
87+
if !nodeGroup.GetDiskSize().Equal(attrs.DiskSize) {
8888
return nil, fmt.Errorf("node group diskSize does not match create args: '%s' != '%s'", nodeGroup.GetDiskSize(), attrs.DiskSize)
8989
}
9090

@@ -121,7 +121,7 @@ func ValidateClusterNodeGroups(ctx context.Context, client CloudMaintainKubernet
121121
if clusterNodeGroup.GetInstanceType() != nodeGroup.GetInstanceType() {
122122
return fmt.Errorf("cluster node group instanceType does not match create args: '%s' != '%s'", clusterNodeGroup.GetInstanceType(), nodeGroup.GetInstanceType())
123123
}
124-
if clusterNodeGroup.GetDiskSize() != nodeGroup.GetDiskSize() {
124+
if !clusterNodeGroup.GetDiskSize().Equal(nodeGroup.GetDiskSize()) {
125125
return fmt.Errorf("cluster node group diskSize does not match create args: '%s' != '%s'", clusterNodeGroup.GetDiskSize(), nodeGroup.GetDiskSize())
126126
}
127127
for key, value := range nodeGroup.GetTags() {

v1/providers/aws/kubernetes.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
)
2626

2727
var (
28+
minDiskSize = v1.NewBytes(20, v1.Gibibyte)
29+
2830
errUsernameIsRequired = fmt.Errorf("username is required")
2931
errRoleIsRequired = fmt.Errorf("role is required")
3032
errClusterIDIsRequired = fmt.Errorf("cluster ID is required")
@@ -34,7 +36,7 @@ var (
3436
errNodeGroupMaxNodeCountMustBeGreaterThan0 = fmt.Errorf("node group maxNodeCount must be greater than 0")
3537
errNodeGroupMaxNodeCountMustBeGreaterThanOrEqualToMinNodeCount = fmt.Errorf("node group maxNodeCount must be greater than or equal to minNodeCount")
3638
errNodeGroupInstanceTypeIsRequired = fmt.Errorf("node group instanceType is required")
37-
errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualTo20 = fmt.Errorf("node group diskSizeGiB must be greater than or equal to 20")
39+
errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualToMinDiskSize = fmt.Errorf("node group diskSizeGiB must be greater than or equal to %v", minDiskSize)
3840
errNodeGroupDiskSizeGiBMustBeLessThanOrEqualToMaxInt32 = fmt.Errorf("node group diskSizeGiB must be less than or equal to %d", math.MaxInt32)
3941
errNodeGroupMaxNodeCountMustBeLessThanOrEqualToMaxInt32 = fmt.Errorf("node group maxNodeCount must be less than or equal to %d", math.MaxInt32)
4042
errNodeGroupMinNodeCountMustBeLessThanOrEqualToMaxInt32 = fmt.Errorf("node group minNodeCount must be less than or equal to %d", math.MaxInt32)
@@ -518,8 +520,8 @@ func validateCreateNodeGroupArgs(args v1.CreateNodeGroupArgs) error {
518520
if args.InstanceType == "" {
519521
errs = append(errs, errNodeGroupInstanceTypeIsRequired)
520522
}
521-
if args.DiskSize.LessThan(v1.NewBytes(20, v1.Gibibyte)) {
522-
errs = append(errs, errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualTo20)
523+
if args.DiskSize.LessThan(minDiskSize) {
524+
errs = append(errs, errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualToMinDiskSize)
523525
}
524526
if args.DiskSize.GreaterThan(v1.NewBytes(math.MaxInt32, v1.Gibibyte)) {
525527
errs = append(errs, errNodeGroupDiskSizeGiBMustBeLessThanOrEqualToMaxInt32)

v1/providers/aws/kubernetes_unit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestValidateCreateNodeGroupArgs(t *testing.T) { //nolint:funlen // test ok
8989
InstanceType: "t3.medium",
9090
DiskSize: v1.NewBytes(10, v1.Gibibyte),
9191
},
92-
expectError: errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualTo20,
92+
expectError: errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualToMinDiskSize,
9393
},
9494
{
9595
name: "disk size exceeds max int32",

0 commit comments

Comments
 (0)