This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
env_vars_integration_test.go
183 lines (137 loc) · 5.57 KB
/
env_vars_integration_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build integration
package travis
import (
"context"
"net/http"
"testing"
"time"
)
const integrationEnvVarId = "88ee9d56-62bb-4093-a278-0c5cfd1e5cd5"
func TestEnvVarsService_Integration_FindByRepoId(t *testing.T) {
envVar, res, err := integrationClient.EnvVars.FindByRepoId(context.TODO(), integrationRepoId, integrationEnvVarId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("invalid http status: %s", res.Status)
}
if *envVar.Id != integrationEnvVarId {
t.Fatalf("unexpected env var id returned: want %s got %s", integrationEnvVarId, *envVar.Id)
}
}
func TestEnvVarsService_Integration_FindByRepoSlug(t *testing.T) {
envVar, res, err := integrationClient.EnvVars.FindByRepoSlug(context.TODO(), integrationRepoSlug, integrationEnvVarId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("invalid http status: %s", res.Status)
}
if *envVar.Id != integrationEnvVarId {
t.Fatalf("unexpected env var id returned: want %s got %s", integrationEnvVarId, *envVar.Id)
}
}
func TestEnvVarsService_Integration_ListByRepoId(t *testing.T) {
vars, res, err := integrationClient.EnvVars.ListByRepoId(context.TODO(), integrationRepoId)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("invalid http status: %s", res.Status)
}
if len(vars) == 0 {
t.Fatal("env vars are not supposed to be empty")
}
}
func TestEnvVarsService_Integration_ListByRepoSlug(t *testing.T) {
vars, res, err := integrationClient.EnvVars.ListByRepoSlug(context.TODO(), integrationRepoSlug)
if err != nil {
t.Fatalf("unexpected error occured: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("invalid http status: %s", res.Status)
}
if len(vars) == 0 {
t.Fatal("env vars are not supposed to be empty")
}
}
func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoId(t *testing.T) {
// Create
body := EnvVarBody{Name: "TEST", Value: "test", Public: true, Branch: "foo"}
envVar, res, err := integrationClient.EnvVars.CreateByRepoId(context.TODO(), integrationRepoId, &body)
if err != nil {
t.Fatalf("EnvVars.CreateByRepoId returned unexpected error: %s", err)
}
if res.StatusCode != http.StatusCreated {
t.Fatalf("EnvVars.CreateByRepoId returned invalid http status: %s", res.Status)
}
if *envVar.Name != body.Name || *envVar.Value != body.Value || *envVar.Public != body.Public || *envVar.Branch != body.Branch {
t.Fatalf("EnvVars.CreateByRepoId returned invalid EnvVar: %v", envVar)
}
// Be nice to the API
time.Sleep(2 * time.Second)
// Update
body = EnvVarBody{Name: "NEW_TEST", Value: "new_test", Public: false, Branch: "bar"}
envVar, res, err = integrationClient.EnvVars.UpdateByRepoId(context.TODO(), integrationRepoId, *envVar.Id, &body)
if err != nil {
t.Fatalf("EnvVars.UpdateByRepoId returned unexpected error: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("EnvVars.UpdateByRepoId returned invalid http status: %s", res.Status)
}
if *envVar.Name != body.Name || envVar.Value != nil || *envVar.Public != body.Public || *envVar.Branch != body.Branch {
t.Fatalf("EnvVars.UpdateByRepoId returned invalid EnvVar: %v", envVar)
}
// Be nice to the API
time.Sleep(2 * time.Second)
// Delete
res, err = integrationClient.EnvVars.DeleteByRepoId(context.TODO(), integrationRepoId, *envVar.Id)
if err != nil {
t.Fatalf("EnvVars.DeleteByRepoId returned unexpected error: %s", err)
}
if res.StatusCode != http.StatusNoContent {
t.Fatalf("EnvVars.DeleteByRepoId returned invalid http status: %s", res.Status)
}
}
func TestEnvVarsService_Integration_CreateAndUpdateAndDeleteEnvVarByRepoSlug(t *testing.T) {
// Create
body := EnvVarBody{Name: "TEST", Value: "test", Public: true, Branch: "foo"}
envVar, res, err := integrationClient.EnvVars.CreateByRepoSlug(context.TODO(), integrationRepoSlug, &body)
if err != nil {
t.Fatalf("EnvVars.CreateByRepoSlug returned unexpected error: %s", err)
}
if res.StatusCode != http.StatusCreated {
t.Fatalf("EnvVars.CreateByRepoSlug returned invalid http status: %s", res.Status)
}
if *envVar.Name != body.Name || *envVar.Value != body.Value || *envVar.Public != body.Public || *envVar.Branch != body.Branch {
t.Fatalf("EnvVars.CreateByRepoSlug returned invalid EnvVar: %v", envVar)
}
// Be nice to the API
time.Sleep(2 * time.Second)
// Update
body = EnvVarBody{Name: "NEW_TEST", Value: "new_test", Public: false, Branch: "bar"}
envVar, res, err = integrationClient.EnvVars.UpdateByRepoSlug(context.TODO(), integrationRepoSlug, *envVar.Id, &body)
if err != nil {
t.Fatalf("EnvVar.UpdateByRepoSlug returned unexpected error: %s", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("EnvVar.UpdateByRepoSlug returned invalid http status: %s", res.Status)
}
if *envVar.Name != body.Name || envVar.Value != nil || *envVar.Public != body.Public || *envVar.Branch != body.Branch {
t.Fatalf("EnvVars.UpdateByRepoSlug returned invalid EnvVar: %v", envVar)
}
// Be nice to the API
time.Sleep(2 * time.Second)
// Delete
res, err = integrationClient.EnvVars.DeleteByRepoSlug(context.TODO(), integrationRepoSlug, *envVar.Id)
if err != nil {
t.Fatalf("EnvVars.DeleteByRepoSlug returned unexpected error: %s", err)
}
if res.StatusCode != http.StatusNoContent {
t.Fatalf("EnvVars.DeleteByRepoSlug returned invalid http status: %s", res.Status)
}
}