-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from weaveworks/nginx-tests
Add nginx e2e and unit tests
- Loading branch information
Showing
11 changed files
with
494 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package router | ||
|
||
import ( | ||
"fmt" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
func TestIngressRouter_Reconcile(t *testing.T) { | ||
mocks := setupfakeClients() | ||
router := &IngressRouter{ | ||
logger: mocks.logger, | ||
kubeClient: mocks.kubeClient, | ||
} | ||
|
||
err := router.Reconcile(mocks.ingressCanary) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
canaryAn := "nginx.ingress.kubernetes.io/canary" | ||
canaryWeightAn := "nginx.ingress.kubernetes.io/canary-weight" | ||
|
||
canaryName := fmt.Sprintf("%s-canary", mocks.ingressCanary.Spec.IngressRef.Name) | ||
inCanary, err := router.kubeClient.ExtensionsV1beta1().Ingresses("default").Get(canaryName, metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if _, ok := inCanary.Annotations[canaryAn]; !ok { | ||
t.Errorf("Canary annotation missing") | ||
} | ||
|
||
// test initialisation | ||
if inCanary.Annotations[canaryAn] != "false" { | ||
t.Errorf("Got canary annotation %v wanted false", inCanary.Annotations[canaryAn]) | ||
} | ||
|
||
if inCanary.Annotations[canaryWeightAn] != "0" { | ||
t.Errorf("Got canary weight annotation %v wanted 0", inCanary.Annotations[canaryWeightAn]) | ||
} | ||
} | ||
|
||
func TestIngressRouter_GetSetRoutes(t *testing.T) { | ||
mocks := setupfakeClients() | ||
router := &IngressRouter{ | ||
logger: mocks.logger, | ||
kubeClient: mocks.kubeClient, | ||
} | ||
|
||
err := router.Reconcile(mocks.ingressCanary) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
p, c, err := router.GetRoutes(mocks.ingressCanary) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
p = 50 | ||
c = 50 | ||
|
||
err = router.SetRoutes(mocks.ingressCanary, p, c) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
canaryAn := "nginx.ingress.kubernetes.io/canary" | ||
canaryWeightAn := "nginx.ingress.kubernetes.io/canary-weight" | ||
|
||
canaryName := fmt.Sprintf("%s-canary", mocks.ingressCanary.Spec.IngressRef.Name) | ||
inCanary, err := router.kubeClient.ExtensionsV1beta1().Ingresses("default").Get(canaryName, metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if _, ok := inCanary.Annotations[canaryAn]; !ok { | ||
t.Errorf("Canary annotation missing") | ||
} | ||
|
||
// test rollout | ||
if inCanary.Annotations[canaryAn] != "true" { | ||
t.Errorf("Got canary annotation %v wanted true", inCanary.Annotations[canaryAn]) | ||
} | ||
|
||
if inCanary.Annotations[canaryWeightAn] != "50" { | ||
t.Errorf("Got canary weight annotation %v wanted 50", inCanary.Annotations[canaryWeightAn]) | ||
} | ||
|
||
p = 100 | ||
c = 0 | ||
|
||
err = router.SetRoutes(mocks.ingressCanary, p, c) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
inCanary, err = router.kubeClient.ExtensionsV1beta1().Ingresses("default").Get(canaryName, metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
// test promotion | ||
if inCanary.Annotations[canaryAn] != "false" { | ||
t.Errorf("Got canary annotation %v wanted false", inCanary.Annotations[canaryAn]) | ||
} | ||
|
||
if inCanary.Annotations[canaryWeightAn] != "0" { | ||
t.Errorf("Got canary weight annotation %v wanted 0", inCanary.Annotations[canaryWeightAn]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: podinfo | ||
namespace: test | ||
labels: | ||
app: podinfo | ||
annotations: | ||
kubernetes.io/ingress.class: "nginx" | ||
spec: | ||
rules: | ||
- host: app.example.com | ||
http: | ||
paths: | ||
- backend: | ||
serviceName: podinfo | ||
servicePort: 9898 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
|
||
REPO_ROOT=$(git rev-parse --show-toplevel) | ||
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" | ||
|
||
echo '>>> Building Flagger' | ||
cd ${REPO_ROOT} && docker build -t test/flagger:latest . -f Dockerfile | ||
|
||
echo '>>> Installing Flagger' | ||
kind load docker-image test/flagger:latest | ||
|
||
echo '>>> Installing Flagger' | ||
helm upgrade -i flagger ${REPO_ROOT}/charts/flagger \ | ||
--wait \ | ||
--namespace ingress-nginx \ | ||
--set prometheus.install=true \ | ||
--set meshProvider=nginx | ||
|
||
kubectl -n ingress-nginx set image deployment/flagger flagger=test/flagger:latest | ||
|
||
kubectl -n ingress-nginx rollout status deployment/flagger | ||
kubectl -n ingress-nginx rollout status deployment/flagger-prometheus |
Oops, something went wrong.