Skip to content

Commit f6144dd

Browse files
committed
unit tests
1 parent b0fd928 commit f6144dd

7 files changed

Lines changed: 1536 additions & 36 deletions

File tree

v1/providers/aws/kubernetes.go

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ import (
2424
v1 "github.com/brevdev/cloud/v1"
2525
)
2626

27+
var (
28+
errUsernameIsRequired = fmt.Errorf("username is required")
29+
errRoleIsRequired = fmt.Errorf("role is required")
30+
errClusterIDIsRequired = fmt.Errorf("cluster ID is required")
31+
errRSAPEMBase64IsRequired = fmt.Errorf("RSA PEM base64 is required")
32+
33+
errNodeGroupMinNodeCountMustBeGreaterThan0 = fmt.Errorf("node group minNodeCount must be greater than 0")
34+
errNodeGroupMaxNodeCountMustBeGreaterThan0 = fmt.Errorf("node group maxNodeCount must be greater than 0")
35+
errNodeGroupMaxNodeCountMustBeGreaterThanOrEqualToMinNodeCount = fmt.Errorf("node group maxNodeCount must be greater than or equal to minNodeCount")
36+
errNodeGroupInstanceTypeIsRequired = fmt.Errorf("node group instanceType is required")
37+
errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualTo20 = fmt.Errorf("node group diskSizeGiB must be greater than or equal to 20")
38+
errNodeGroupDiskSizeGiBMustBeLessThanOrEqualToMaxInt32 = fmt.Errorf("node group diskSizeGiB must be less than or equal to %d", math.MaxInt32)
39+
errNodeGroupMaxNodeCountMustBeLessThanOrEqualToMaxInt32 = fmt.Errorf("node group maxNodeCount must be less than or equal to %d", math.MaxInt32)
40+
errNodeGroupMinNodeCountMustBeLessThanOrEqualToMaxInt32 = fmt.Errorf("node group minNodeCount must be less than or equal to %d", math.MaxInt32)
41+
)
42+
2743
var _ v1.CloudMaintainKubernetes = &AWSClient{}
2844

2945
const iamRolePathPrefix = "/brevcloudsdk/eks/clusters"
@@ -484,28 +500,28 @@ func (c *AWSClient) CreateNodeGroup(ctx context.Context, args v1.CreateNodeGroup
484500
func validateCreateNodeGroupArgs(args v1.CreateNodeGroupArgs) error {
485501
errs := []error{}
486502
if args.MinNodeCount < 1 {
487-
errs = append(errs, fmt.Errorf("node group minNodeCount must be greater than 0"))
503+
errs = append(errs, errNodeGroupMinNodeCountMustBeGreaterThan0)
488504
}
489505
if args.MaxNodeCount < 1 {
490-
errs = append(errs, fmt.Errorf("node group maxNodeCount must be greater than 0"))
506+
errs = append(errs, errNodeGroupMaxNodeCountMustBeGreaterThan0)
491507
}
492508
if args.MaxNodeCount < args.MinNodeCount {
493-
errs = append(errs, fmt.Errorf("node group maxNodeCount must be greater than or equal to minNodeCount"))
509+
errs = append(errs, errNodeGroupMaxNodeCountMustBeGreaterThanOrEqualToMinNodeCount)
494510
}
495511
if args.InstanceType == "" {
496-
errs = append(errs, fmt.Errorf("node group instanceType is required"))
512+
errs = append(errs, errNodeGroupInstanceTypeIsRequired)
497513
}
498514
if args.DiskSizeGiB < 20 {
499-
errs = append(errs, fmt.Errorf("node group diskSizeGiB must be greater than or equal to 20"))
515+
errs = append(errs, errNodeGroupDiskSizeGiBMustBeGreaterThanOrEqualTo20)
500516
}
501517
if args.DiskSizeGiB > math.MaxInt32 {
502-
errs = append(errs, fmt.Errorf("node group diskSizeGiB must be less than or equal to %d", math.MaxInt32))
518+
errs = append(errs, errNodeGroupDiskSizeGiBMustBeLessThanOrEqualToMaxInt32)
503519
}
504520
if args.MaxNodeCount > math.MaxInt32 {
505-
errs = append(errs, fmt.Errorf("node group maxNodeCount must be less than or equal to %d", math.MaxInt32))
521+
errs = append(errs, errNodeGroupMaxNodeCountMustBeLessThanOrEqualToMaxInt32)
506522
}
507523
if args.MinNodeCount > math.MaxInt32 {
508-
errs = append(errs, fmt.Errorf("node group minNodeCount must be less than or equal to %d", math.MaxInt32))
524+
errs = append(errs, errNodeGroupMinNodeCountMustBeLessThanOrEqualToMaxInt32)
509525
}
510526
return errors.WrapAndTrace(errors.Join(errs...))
511527
}
@@ -638,19 +654,19 @@ func (c *AWSClient) ModifyNodeGroup(ctx context.Context, args v1.ModifyNodeGroup
638654
func validateModifyNodeGroupArgs(args v1.ModifyNodeGroupArgs) error {
639655
errs := []error{}
640656
if args.MinNodeCount < 1 {
641-
errs = append(errs, fmt.Errorf("node group minNodeCount must be greater than 0"))
657+
errs = append(errs, errNodeGroupMinNodeCountMustBeGreaterThan0)
642658
}
643659
if args.MaxNodeCount < 1 {
644-
errs = append(errs, fmt.Errorf("node group maxNodeCount must be greater than 0"))
660+
errs = append(errs, errNodeGroupMaxNodeCountMustBeGreaterThan0)
645661
}
646662
if args.MaxNodeCount < args.MinNodeCount {
647-
errs = append(errs, fmt.Errorf("node group maxNodeCount must be greater than or equal to minNodeCount"))
663+
errs = append(errs, errNodeGroupMaxNodeCountMustBeGreaterThanOrEqualToMinNodeCount)
648664
}
649665
if args.MinNodeCount > math.MaxInt32 {
650-
errs = append(errs, fmt.Errorf("node group minNodeCount must be less than or equal to %d", math.MaxInt32))
666+
errs = append(errs, errNodeGroupMinNodeCountMustBeLessThanOrEqualToMaxInt32)
651667
}
652668
if args.MaxNodeCount > math.MaxInt32 {
653-
errs = append(errs, fmt.Errorf("node group maxNodeCount must be less than or equal to %d", math.MaxInt32))
669+
errs = append(errs, errNodeGroupMaxNodeCountMustBeLessThanOrEqualToMaxInt32)
654670
}
655671
return errors.WrapAndTrace(errors.Join(errs...))
656672
}
@@ -816,16 +832,16 @@ func (c *AWSClient) SetClusterUser(ctx context.Context, args v1.SetClusterUserAr
816832
func validatePutUserArgs(args v1.SetClusterUserArgs) error {
817833
errs := []error{}
818834
if args.Username == "" {
819-
errs = append(errs, fmt.Errorf("username is required"))
835+
errs = append(errs, errUsernameIsRequired)
820836
}
821837
if args.Role == "" {
822-
errs = append(errs, fmt.Errorf("role is required"))
838+
errs = append(errs, errRoleIsRequired)
823839
}
824840
if args.ClusterID == "" {
825-
errs = append(errs, fmt.Errorf("cluster ID is required"))
841+
errs = append(errs, errClusterIDIsRequired)
826842
}
827843
if args.RSAPEMBase64 == "" {
828-
errs = append(errs, fmt.Errorf("RSA PEM base64 is required"))
844+
errs = append(errs, errRSAPEMBase64IsRequired)
829845
}
830846
return errors.WrapAndTrace(errors.Join(errs...))
831847
}

0 commit comments

Comments
 (0)