-
Notifications
You must be signed in to change notification settings - Fork 28
/
service_task_acc_test.go
100 lines (83 loc) · 2.48 KB
/
service_task_acc_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
88
89
90
91
92
93
94
95
96
97
98
99
100
package aiven
import (
"context"
"math/rand"
"os"
"strconv"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Service Task", func() {
var (
projectName string
)
ctx := context.Background()
Context("PG Service Task", func() {
It("should not error", func() {
projectName = os.Getenv("AIVEN_PROJECT_NAME")
_, err := client.Projects.Get(ctx, projectName)
Expect(err).NotTo(HaveOccurred())
})
// PG service
var (
serviceName string
service *Service
errS error
)
It("creating service", func() {
serviceName = "test-acc-pg-sr-" + strconv.Itoa(rand.Int())
service, errS = client.Services.Create(ctx, projectName, CreateServiceRequest{
Cloud: "google-europe-west1",
Plan: "business-4",
ProjectVPCID: nil,
ServiceName: serviceName,
ServiceType: "pg",
UserConfig: map[string]interface{}{
"pg_version": "11",
},
})
})
It("should not error", func() {
Expect(errS).NotTo(HaveOccurred())
})
It("should populate fields properly", func() {
Expect(service).NotTo(BeNil())
if service != nil {
Expect(service.Name).NotTo(BeEmpty())
Expect(service.Plan).NotTo(BeEmpty())
Expect(service.Type).Should(Equal("pg"))
Eventually(func() string {
service, _ = client.Services.Get(ctx, projectName, serviceName)
return service.State
}, 25*time.Minute, 1*time.Minute).Should(Equal("RUNNING"))
}
})
// service task
It("create pg service task", func() {
t, errT := client.ServiceTask.Create(ctx, projectName, serviceName, ServiceTaskRequest{
TargetVersion: "12",
TaskType: "upgrade_check",
})
Expect(errT).NotTo(HaveOccurred())
Expect(t.Task.CreateTime).NotTo(BeEmpty())
Expect(t.Task.Id).NotTo(BeEmpty())
Expect(t.Task.Result).NotTo(BeEmpty())
Expect(t.Task.SourcePgVersion).NotTo(BeEmpty())
Expect(t.Task.TargetPgVersion).NotTo(BeEmpty())
Expect(t.Task.TaskType).NotTo(BeEmpty())
Eventually(func() *bool {
t, errT = client.ServiceTask.Get(ctx, projectName, serviceName, t.Task.Id)
return t.Task.Success
}, 5*time.Minute, 15*time.Second).Should(Not(BeNil()))
t, errT = client.ServiceTask.Get(ctx, projectName, serviceName, t.Task.Id)
Expect(errT).NotTo(HaveOccurred())
Expect(*t.Task.Success).To(BeTrue())
})
It("delete PG service", func() {
if errD := client.Services.Delete(ctx, projectName, serviceName); errD != nil {
Fail("cannot delete service:" + errD.Error())
}
})
})
})