Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Mar 28, 2019
1 parent bec8ad3 commit 5cbb187
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 299 deletions.
243 changes: 243 additions & 0 deletions pkg/ctl/cmdutils/nodegroup_filter_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cmdutils_test

import (
"bytes"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha4"
"github.com/weaveworks/eksctl/pkg/printers"

. "github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
)
Expand All @@ -13,6 +16,48 @@ var _ = Describe("nodegroup filter", func() {

Context("CheckEachNodeGroup", func() {

It("should iterate over unique nodegroups and apply defaults with NewNodeGroupChecker", func() {
cfg := newClusterConfig()
addGroupA(cfg)
addGroupB(cfg)

filter := NewNodeGroupFilter()
printer := printers.NewJSONPrinter()
names := []string{}

filter.ValidateNodeGroupsAndSetDefaults(cfg.NodeGroups)

filter.CheckEachNodeGroup(cfg.NodeGroups, func(i int, nodeGroup *api.NodeGroup) error {
Expect(nodeGroup).To(Equal(cfg.NodeGroups[i]))
names = append(names, nodeGroup.Name)
return nil
})
Expect(names).To(Equal([]string{"test-ng1a", "test-ng2a", "test-ng3a", "test-ng1b", "test-ng2b", "test-ng3b"}))

w := &bytes.Buffer{}

printer.PrintObj(cfg, w)

Expect(w.Bytes()).To(MatchJSON(expected))
})

It("should be able to skip all nodegroups", func() {
cfg := newClusterConfig()
addGroupA(cfg)
addGroupB(cfg)

filter := NewNodeGroupFilter()
filter.SkipAll = true
filter.ValidateNodeGroupsAndSetDefaults(cfg.NodeGroups)

callback := false
filter.CheckEachNodeGroup(cfg.NodeGroups, func(_ int, _ *api.NodeGroup) error {
callback = true
return nil
})
Expect(callback).To(BeFalse())
})

It("should iterate over unique nodegroups", func() {
cfg := newClusterConfig()
addGroupA(cfg)
Expand Down Expand Up @@ -128,3 +173,201 @@ func addGroupB(cfg *api.ClusterConfig) {
ng.SecurityGroups.WithLocal = api.NewBoolFalse()
ng.Labels = map[string]string{"group": "b", "seq": "1"}
}

const expected = `
{
"kind": "ClusterConfig",
"apiVersion": "eksctl.io/v1alpha4",
"metadata": {
"name": "test-3x3-ngs",
"region": "eu-central-1",
"version": "1.11"
},
"iam": {},
"vpc": {
"cidr": "192.168.0.0/16"
},
"nodeGroups": [
{
"name": "test-ng1a",
"ami": "static",
"amiFamily": "AmazonLinux2",
"instanceType": "m5.large",
"privateNetworking": false,
"securityGroups": {
"withShared": true,
"withLocal": true
},
"volumeSize": 768,
"volumeType": "io1",
"labels": {
"group": "a",
"seq": "1"
},
"allowSSH": false,
"iam": {
"attachPolicyARNs": [
"foo"
],
"withAddonPolicies": {
"imageBuilder": false,
"autoScaler": false,
"externalDNS": false,
"appMesh": false,
"ebs": false
}
}
},
{
"name": "test-ng2a",
"ami": "static",
"amiFamily": "AmazonLinux2",
"instanceType": "m5.large",
"privateNetworking": false,
"securityGroups": {
"withShared": true,
"withLocal": true
},
"volumeSize": 0,
"volumeType": "gp2",
"labels": {
"group": "a",
"seq": "2"
},
"allowSSH": false,
"iam": {
"attachPolicyARNs": [
"bar"
],
"withAddonPolicies": {
"imageBuilder": false,
"autoScaler": false,
"externalDNS": false,
"appMesh": false,
"ebs": false
}
}
},
{
"name": "test-ng3a",
"ami": "static",
"amiFamily": "AmazonLinux2",
"instanceType": "m3.large",
"privateNetworking": false,
"securityGroups": {
"withShared": true,
"withLocal": true
},
"volumeSize": 0,
"volumeType": "gp2",
"labels": {
"group": "a",
"seq": "3"
},
"allowSSH": true,
"sshPublicKeyPath": "~/.ssh/id_rsa.pub",
"iam": {
"withAddonPolicies": {
"imageBuilder": false,
"autoScaler": false,
"externalDNS": false,
"appMesh": false,
"ebs": false
}
},
"clusterDNS": "1.2.3.4"
},
{
"name": "test-ng1b",
"ami": "static",
"amiFamily": "AmazonLinux2",
"instanceType": "m5.large",
"privateNetworking": false,
"securityGroups": {
"withShared": true,
"withLocal": true
},
"volumeSize": 0,
"volumeType": "gp2",
"labels": {
"group": "b",
"seq": "1"
},
"allowSSH": true,
"sshPublicKeyPath": "~/.ssh/id_rsa.pub",
"iam": {
"withAddonPolicies": {
"imageBuilder": false,
"autoScaler": false,
"externalDNS": false,
"appMesh": false,
"ebs": false
}
}
},
{
"name": "test-ng2b",
"ami": "static",
"amiFamily": "AmazonLinux2",
"instanceType": "m5.xlarge",
"privateNetworking": false,
"securityGroups": {
"attachIDs": [
"sg-1",
"sg-2"
],
"withShared": true,
"withLocal": false
},
"volumeSize": 0,
"volumeType": "gp2",
"labels": {
"group": "b",
"seq": "1"
},
"allowSSH": false,
"iam": {
"withAddonPolicies": {
"imageBuilder": false,
"autoScaler": false,
"externalDNS": false,
"appMesh": false,
"ebs": false
}
},
"clusterDNS": "4.2.8.14"
},
{
"name": "test-ng3b",
"ami": "static",
"amiFamily": "AmazonLinux2",
"instanceType": "m5.large",
"privateNetworking": false,
"securityGroups": {
"attachIDs": [
"sg-1",
"sg-2"
],
"withShared": true,
"withLocal": false
},
"volumeSize": 192,
"volumeType": "gp2",
"labels": {
"group": "b",
"seq": "1"
},
"allowSSH": false,
"iam": {
"withAddonPolicies": {
"imageBuilder": false,
"autoScaler": false,
"externalDNS": false,
"appMesh": false,
"ebs": false
}
}
}
]
}
`
Loading

0 comments on commit 5cbb187

Please sign in to comment.