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
/
Copy pathtest.go
64 lines (54 loc) · 1.73 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
package argorollouts
import (
"context"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/flanksource/commons/console"
"github.com/flanksource/karina/pkg/constants"
"github.com/flanksource/karina/pkg/platform"
"github.com/flanksource/kommons"
)
const (
TestNamespace = "test-argorollouts"
)
func Test(p *platform.Platform, test *console.TestResults) {
if p.ArgoRollouts.IsDisabled() {
return
}
client, _ := p.GetClientset()
kommons.TestDeploy(client, constants.PlatformSystem, "argo-rollouts", test)
if p.E2E {
TestE2E(p, test)
}
}
func TestE2E(p *platform.Platform, test *console.TestResults) {
testName := "argorollouts-e2e"
rolloutName := "rollouts-demo"
defer removeE2ETestResources(p, test)
if err := p.CreateOrUpdateNamespace(TestNamespace, nil, nil); err != nil {
test.Failf(testName, "Failed to create test namespace %s", TestNamespace)
return
}
if err := p.ApplySpecs(TestNamespace, "test/argo-rollouts.yaml"); err != nil {
test.Failf(testName, "%v", err)
return
}
if _, err := p.WaitForResource("Rollout", TestNamespace, rolloutName, 2*time.Minute); err != nil {
test.Failf(testName, "argo rollout is not ready: %s", err)
return
}
test.Passf(testName, "argo rollout is ready")
}
func removeE2ETestResources(p *platform.Platform, test *console.TestResults) {
if p.PlatformConfig.Trace {
return
}
if err := p.DeleteSpecs(TestNamespace, "test/argo-rollouts.yaml"); err != nil {
test.Warnf("Failed to cleanup Argo Rollouts test resources in namespace %s", TestNamespace)
}
client, _ := p.GetClientset()
err := client.CoreV1().Namespaces().Delete(context.TODO(), TestNamespace, metav1.DeleteOptions{})
if err != nil {
test.Warnf("Failed to delete test namespace %s", TestNamespace)
}
}