This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
test.go
66 lines (53 loc) · 1.62 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package quack
import (
"context"
"fmt"
"github.com/flanksource/commons/console"
"github.com/flanksource/commons/utils"
"github.com/flanksource/karina/pkg/platform"
"github.com/flanksource/kommons"
"k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func Test(platform *platform.Platform, test *console.TestResults) {
if platform.Quack != nil && platform.Quack.Disabled {
return
}
client, _ := platform.GetClientset()
kommons.TestNamespace(client, Namespace, test)
if !platform.E2E {
return
}
namespace := fmt.Sprintf("quack-test-%s", utils.RandomKey(6))
if err := platform.CreateOrUpdateWorkloadNamespace(namespace, EnabledLabels, nil); err != nil {
test.Failf("quack", "Failed to create test namespace %s: %v", namespace, err)
return
}
defer func() {
client.CoreV1().Namespaces().Delete(context.TODO(), namespace, metav1.DeleteOptions{}) // nolint: errcheck
}()
ingresses := client.NetworkingV1beta1().Ingresses(namespace)
ingress, err := ingresses.Create(context.TODO(), &v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Namespace: namespace,
},
Spec: v1beta1.IngressSpec{
Rules: []v1beta1.IngressRule{
{
Host: namespace + ".{{.domain}}",
},
},
},
}, metav1.CreateOptions{})
if err != nil {
test.Failf("quack", "failed to create ingress: %v", err)
return
}
exptecedHost := namespace + "." + platform.Domain
if ingress.Spec.Rules[0].Host != exptecedHost {
test.Failf("quack", "expected %s, got %s", exptecedHost, ingress.Spec.Rules[0].Host)
} else {
test.Passf("quack", "quack templated ingress successfully")
}
}