-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline_test.go
87 lines (77 loc) · 2.41 KB
/
pipeline_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package ks_devops_e2e
import (
"bytes"
"context"
"github.com/Pallinder/go-randomdata"
"github.com/kubesphere-sigs/ks-devops-e2e/pkg"
"github.com/linuxsuren/http-downloader/pkg/exec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"strings"
"time"
)
var _ = Describe("Pipeline Test", func() {
stdout := &bytes.Buffer{}
errout := &bytes.Buffer{}
var (
ws, project, name, template string
namespace string
)
ws = strings.ToLower(randomdata.SillyName())
project = strings.ToLower(randomdata.SillyName())
name = strings.ToLower(randomdata.SillyName())
template = "simple"
Context("Create and run pipeline", func() {
It("Create Pipeline", func() {
err := exec.RunCommandWithIO("ks", "", stdout, errout, "pip", "create", "--ws", ws,
"--template", template, "--name", name, "--project", project)
Expect(err).To(BeNil())
result := errout.String()
Expect(result).To(BeEmpty())
client, _, err := GetClient()
Expect(err).To(BeNil())
Eventually(func() bool {
var pipelineList *unstructured.UnstructuredList
if pipelineList, err = client.Resource(pkg.GetPipelineSchema()).List(context.TODO(), metav1.ListOptions{}); err != nil {
return false
}
for i := range pipelineList.Items {
item := pipelineList.Items[i]
if item.GetName() == name {
namespace = item.GetNamespace()
return true
}
}
return false
}, time.Minute * 2, time.Second * 3).Should(BeTrue())
})
It("Run a Pipeline", func() {
err := exec.RunCommandWithIO("ks", "", stdout, errout, "pip", "run", "--project", project,
"-p", name, "-b")
Expect(err).To(BeNil())
result := errout.String()
Expect(result).To(BeEmpty())
client, _, err := GetClient()
Expect(err).To(BeNil())
Eventually(func() bool {
var pipelineRuns *unstructured.UnstructuredList
if pipelineRuns, err = client.Resource(pkg.GetPipelineRunSchema()).Namespace(namespace).List(context.TODO(), metav1.ListOptions{}); err != nil {
return false
}
for i := range pipelineRuns.Items {
item := pipelineRuns.Items[i]
if item.GetGenerateName() == name {
phase := getNestedString(item.Object, "status", "phase")
if phase == "Succeeded" {
return true
}
break
}
}
return false
}, time.Minute * 10, time.Second * 3).Should(BeTrue())
})
})
})