Skip to content

Commit 80a87b0

Browse files
Add github endpoint operations e2e test
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 1256473 commit 80a87b0

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

test/integration/e2e/endpoints.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package e2e
22

3+
import (
4+
"os"
5+
6+
"github.com/cloudbase/garm/params"
7+
)
8+
39
func MustDefaultGithubEndpoint() {
410
ep := GetGithubEndpoint("github.com")
511
if ep == nil {
@@ -10,3 +16,94 @@ func MustDefaultGithubEndpoint() {
1016
panic("Default GitHub endpoint name mismatch")
1117
}
1218
}
19+
20+
func checkEndpointParamsAreEqual(a, b params.GithubEndpoint) {
21+
if a.Name != b.Name {
22+
panic("Endpoint name mismatch")
23+
}
24+
25+
if a.Description != b.Description {
26+
panic("Endpoint description mismatch")
27+
}
28+
29+
if a.BaseURL != b.BaseURL {
30+
panic("Endpoint base URL mismatch")
31+
}
32+
33+
if a.APIBaseURL != b.APIBaseURL {
34+
panic("Endpoint API base URL mismatch")
35+
}
36+
37+
if a.UploadBaseURL != b.UploadBaseURL {
38+
panic("Endpoint upload base URL mismatch")
39+
}
40+
41+
if string(a.CACertBundle) != string(b.CACertBundle) {
42+
panic("Endpoint CA cert bundle mismatch")
43+
}
44+
}
45+
46+
func TestGithubEndpointOperations() {
47+
caBundle, err := os.ReadFile("../../testdata/certs/srv-pub.pem")
48+
if err != nil {
49+
panic(err)
50+
}
51+
endpointParams := params.CreateGithubEndpointParams{
52+
Name: "test-endpoint",
53+
Description: "Test endpoint",
54+
BaseURL: "https://ghes.example.com",
55+
APIBaseURL: "https://api.ghes.example.com/",
56+
UploadBaseURL: "https://uploads.ghes.example.com/",
57+
CACertBundle: caBundle,
58+
}
59+
60+
endpoint := CreateGithubEndpoint(endpointParams)
61+
if endpoint.Name != endpointParams.Name {
62+
panic("Endpoint name mismatch")
63+
}
64+
65+
if endpoint.Description != endpointParams.Description {
66+
panic("Endpoint description mismatch")
67+
}
68+
69+
if endpoint.BaseURL != endpointParams.BaseURL {
70+
panic("Endpoint base URL mismatch")
71+
}
72+
73+
if endpoint.APIBaseURL != endpointParams.APIBaseURL {
74+
panic("Endpoint API base URL mismatch")
75+
}
76+
77+
if endpoint.UploadBaseURL != endpointParams.UploadBaseURL {
78+
panic("Endpoint upload base URL mismatch")
79+
}
80+
81+
if string(endpoint.CACertBundle) != string(caBundle) {
82+
panic("Endpoint CA cert bundle mismatch")
83+
}
84+
85+
endpoint2 := GetGithubEndpoint(endpointParams.Name)
86+
if endpoint == nil || endpoint2 == nil {
87+
panic("endpoint is nil")
88+
}
89+
checkEndpointParamsAreEqual(*endpoint, *endpoint2)
90+
91+
endpoints := ListGithubEndpoints()
92+
var found bool
93+
for _, ep := range endpoints {
94+
if ep.Name == endpointParams.Name {
95+
checkEndpointParamsAreEqual(*endpoint, ep)
96+
found = true
97+
break
98+
}
99+
}
100+
if !found {
101+
panic("Endpoint not found in list")
102+
}
103+
104+
DeleteGithubEndpoint(endpoint.Name)
105+
106+
if err := deleteGithubEndpoint(cli, authToken, "github.com"); err == nil {
107+
panic("expected error when attempting to delete the default github.com endpoint")
108+
}
109+
}

test/integration/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func main() {
8181
// Create test credentials
8282
e2e.EnsureTestCredentials(credentialsName, ghToken, "github.com")
8383

84+
// Test endpoint operations
85+
e2e.TestGithubEndpointOperations()
86+
8487
// //////////////////
8588
// controller info //
8689
// //////////////////

0 commit comments

Comments
 (0)