From 8967a3be2c4838b5a0ac505e5b91ee8f402bfae4 Mon Sep 17 00:00:00 2001 From: erthalion <9erthalion6@gmail.com> Date: Tue, 27 Mar 2018 12:11:46 +0200 Subject: [PATCH 1/2] Add tests for load balancer function logic --- pkg/cluster/k8sres_test.go | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 pkg/cluster/k8sres_test.go diff --git a/pkg/cluster/k8sres_test.go b/pkg/cluster/k8sres_test.go new file mode 100644 index 000000000..43405a2ec --- /dev/null +++ b/pkg/cluster/k8sres_test.go @@ -0,0 +1,94 @@ +package cluster + +import ( + "github.com/zalando-incubator/postgres-operator/pkg/spec" + "github.com/zalando-incubator/postgres-operator/pkg/util/config" + "github.com/zalando-incubator/postgres-operator/pkg/util/k8sutil" + "testing" +) + +func True() *bool { + b := true + return &b +} + +func False() *bool { + b := false + return &b +} + +func TestCreateLoadBalancerLogic(t *testing.T) { + var cluster = New( + Config{ + OpConfig: config.Config{ + ProtectedRoles: []string{"admin"}, + Auth: config.Auth{ + SuperUsername: superUserName, + ReplicationUsername: replicationUserName, + }, + }, + }, k8sutil.KubernetesClient{}, spec.Postgresql{}, logger) + + testName := "TestCreateLoadBalancerLogic" + tests := []struct { + subtest string + role PostgresRole + spec *spec.PostgresSpec + opConfig config.Config + result bool + }{ + { + subtest: "new format, load balancer is enabled for replica", + role: Replica, + spec: &spec.PostgresSpec{EnableReplicaLoadBalancer: True()}, + opConfig: config.Config{}, + result: true, + }, + { + subtest: "new format, load balancer is disabled for replica", + role: Replica, + spec: &spec.PostgresSpec{EnableReplicaLoadBalancer: False()}, + opConfig: config.Config{}, + result: false, + }, + { + subtest: "new format, load balancer isn't specified for replica", + role: Replica, + spec: &spec.PostgresSpec{EnableReplicaLoadBalancer: nil}, + opConfig: config.Config{EnableReplicaLoadBalancer: true}, + result: true, + }, + { + subtest: "new format, load balancer isn't specified for replica", + role: Replica, + spec: &spec.PostgresSpec{EnableReplicaLoadBalancer: nil}, + opConfig: config.Config{EnableReplicaLoadBalancer: false}, + result: false, + }, + { + subtest: "old format, load balancer is enabled for replica", + role: Replica, + spec: &spec.PostgresSpec{ReplicaLoadBalancer: True()}, + opConfig: config.Config{}, + result: true, + }, + { + subtest: "old format has priority", + role: Replica, + spec: &spec.PostgresSpec{ + ReplicaLoadBalancer: True(), + EnableReplicaLoadBalancer: False(), + }, + opConfig: config.Config{}, + result: true, + }, + } + for _, tt := range tests { + cluster.OpConfig = tt.opConfig + result := cluster.shouldCreateLoadBalancerForService(tt.role, tt.spec) + if tt.result != result { + t.Errorf("%s %s: Load balancer is %t, expect %t for role %#v and spec %#v", + testName, tt.subtest, result, tt.result, tt.role, tt.spec) + } + } +} From 34518a4eb03a30878d4fd56cc43851ff58db7c3e Mon Sep 17 00:00:00 2001 From: erthalion <9erthalion6@gmail.com> Date: Tue, 27 Mar 2018 16:05:13 +0200 Subject: [PATCH 2/2] Some fixes for travis ci and cdp remove cmd package from travis (it's complaining because there are no tests), and add apt-get update for cdp. --- .travis.yml | 2 +- delivery.yaml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 199408aea..f22275d9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ install: - make deps script: - - travis_wait 20 goveralls -service=travis-ci -package ./pkg/... -package ./cmd/... -v + - travis_wait 20 goveralls -service=travis-ci -package ./pkg/... -v diff --git a/delivery.yaml b/delivery.yaml index d2b176234..502aa75b2 100644 --- a/delivery.yaml +++ b/delivery.yaml @@ -6,6 +6,9 @@ pipeline: GOPATH: /root/go OPERATOR_TOP_DIR: /root/go/src/github.com/zalando-incubator commands: + - desc: 'Update' + cmd: | + apt-get update - desc: 'Install required build software' cmd: | apt-get install -y make git apt-transport-https ca-certificates curl