From a6cc3aed29e4034db71147d5f66d08158fe5dfcd Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sat, 9 Sep 2017 17:36:22 -0300 Subject: [PATCH 1/2] Add badges --- .travis.yml | 4 ++-- README.md | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b8aed78..72a1e18e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,12 +11,12 @@ notifications: go: - 1.9 -go_import_path: github.com/aledbf/kube-keepalived +go_import_path: github.com/aledbf/kube-keepalived-vip env: global: # to add additional secure variables: - # docker run --rm caktux/travis-cli encrypt key=value -r kubernetes/ingress + # docker run --rm caktux/travis-cli encrypt key=value -r kube-keepalived-vip - RELEASE="ci-${TRAVIS_BUILD_ID}" jobs: diff --git a/README.md b/README.md index 685efbc1..b61697fc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ Kubernetes Virtual IP address/es using [keepalived](http://www.keepalived.org) AKA "how to set up virtual IP addresses in kubernetes using [IPVS - The Linux Virtual Server Project](http://www.linuxvirtualserver.org/software/ipvs.html)". +[![Build Status](https://travis-ci.org/aledbf/kube-keepalived.svg?branch=master)](https://travis-ci.org/aledbf/kube-keepalived) +[![Coverage Status](https://coveralls.io/repos/github/aledbf/kube-keepalived/badge.svg?branch=master)](https://coveralls.io/github/aledbf/kube-keepalived) +[![Go Report Card](https://goreportcard.com/badge/github.com/aledbf/kube-keepalived)](https://goreportcard.com/report/github.com/aledbf/kube-keepalived) + ## Overview From c4c396f8087a121036e111d142cd90ffe3f45362 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sat, 9 Sep 2017 17:47:55 -0300 Subject: [PATCH 2/2] Fix tests --- pkg/controller/utils_test.go | 6 +- pkg/k8s/main_test.go | 149 ----------------------------------- 2 files changed, 3 insertions(+), 152 deletions(-) diff --git a/pkg/controller/utils_test.go b/pkg/controller/utils_test.go index 39317b61..18e0265a 100644 --- a/pkg/controller/utils_test.go +++ b/pkg/controller/utils_test.go @@ -26,20 +26,20 @@ func TestParseNsSvcLVS(t *testing.T) { Namespace string Service string ForwardMethod string - ExpectedOk bool + ErrorExpected bool }{ "just service name": {"echoheaders", "", "", "", true}, "missing namespace": {"echoheaders:NAT", "", "", "", true}, "default forward method": {"default/echoheaders", "default", "echoheaders", "NAT", false}, "with forward method": {"default/echoheaders:NAT", "default", "echoheaders", "NAT", false}, - "DR as forward method": {"default/echoheaders:DR", "", "", "", true}, + "DR as forward method": {"default/echoheaders:DR", "default", "echoheaders", "DR", false}, "invalid forward method": {"default/echoheaders:AJAX", "", "", "", true}, } for k, tc := range testcases { ns, svc, lvs, err := parseNsSvcLVS(tc.Input) - if tc.ExpectedOk && err == nil { + if tc.ErrorExpected && err == nil { t.Errorf("%s: expected an error but valid information returned: %v ", k, tc.Input) } diff --git a/pkg/k8s/main_test.go b/pkg/k8s/main_test.go index 820b1216..1c4ed10f 100644 --- a/pkg/k8s/main_test.go +++ b/pkg/k8s/main_test.go @@ -25,155 +25,6 @@ import ( testclient "k8s.io/client-go/kubernetes/fake" ) -func TestParseNameNS(t *testing.T) { - tests := []struct { - title string - input string - ns string - name string - expErr bool - }{ - {"empty string", "", "", "", true}, - {"demo", "demo", "", "", true}, - {"kube-system", "kube-system", "", "", true}, - {"default/kube-system", "default/kube-system", "default", "kube-system", false}, - } - - for _, test := range tests { - ns, name, err := ParseNameNS(test.input) - if test.expErr { - if err == nil { - t.Errorf("%v: expected error but returned nil", test.title) - } - continue - } - if test.ns != ns { - t.Errorf("%v: expected %v but returned %v", test.title, test.ns, ns) - } - if test.name != name { - t.Errorf("%v: expected %v but returned %v", test.title, test.name, name) - } - } -} - -func TestIsValidService(t *testing.T) { - fk := testclient.NewSimpleClientset(&api.Service{ - ObjectMeta: meta_v1.ObjectMeta{ - Namespace: api.NamespaceDefault, - Name: "demo", - }, - }) - - _, err := IsValidService(fk, "") - if err == nil { - t.Errorf("expected error but returned nil") - } - s, err := IsValidService(fk, "default/demo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - if s == nil { - t.Errorf("expected a Service but returned nil") - } - - fk = testclient.NewSimpleClientset() - s, err = IsValidService(fk, "default/demo") - if err == nil { - t.Errorf("expected an error but returned nil") - } - if s != nil { - t.Errorf("unexpected Service returned: %v", s) - } -} - -func TestIsValidNamespace(t *testing.T) { - - fk := testclient.NewSimpleClientset(&api.Namespace{ - ObjectMeta: meta_v1.ObjectMeta{ - Name: "default", - }, - }) - - _, err := IsValidNamespace(fk, "empty") - if err == nil { - t.Errorf("expected error but return nill") - } - - ns, err := IsValidNamespace(fk, "default") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if ns == nil { - t.Errorf("expected a configmap but returned nil") - } - -} - -func TestIsValidConfigMap(t *testing.T) { - - fk := testclient.NewSimpleClientset(&api.ConfigMap{ - ObjectMeta: meta_v1.ObjectMeta{ - Namespace: api.NamespaceDefault, - Name: "demo", - }, - }) - - _, err := IsValidConfigMap(fk, "") - if err == nil { - t.Errorf("expected error but return nill") - } - - s, err := IsValidConfigMap(fk, "default/demo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - - if s == nil { - t.Errorf("expected a configmap but returned nil") - } - - fk = testclient.NewSimpleClientset() - s, err = IsValidConfigMap(fk, "default/demo") - if err == nil { - t.Errorf("expected an error but returned nil") - } - if s != nil { - t.Errorf("unexpected Configmap returned: %v", s) - } - -} - -func TestIsValidSecret(t *testing.T) { - fk := testclient.NewSimpleClientset(&api.Secret{ - ObjectMeta: meta_v1.ObjectMeta{ - Namespace: api.NamespaceDefault, - Name: "demo", - }, - }) - - _, err := IsValidSecret(fk, "") - if err == nil { - t.Errorf("expected error but returned nil") - } - s, err := IsValidSecret(fk, "default/demo") - if err != nil { - t.Errorf("unexpected error: %v", err) - } - if s == nil { - t.Errorf("expected a Secret but returned nil") - } - - fk = testclient.NewSimpleClientset() - s, err = IsValidSecret(fk, "default/demo") - if err == nil { - t.Errorf("expected an error but returned nil") - } - if s != nil { - t.Errorf("unexpected Secret returned: %v", s) - } -} - func TestGetNodeIP(t *testing.T) { fKNodes := []struct { cs *testclient.Clientset