1
1
package e2e
2
2
3
+ import (
4
+ "os"
5
+
6
+ "github.com/cloudbase/garm/params"
7
+ )
8
+
3
9
func MustDefaultGithubEndpoint () {
4
10
ep := GetGithubEndpoint ("github.com" )
5
11
if ep == nil {
@@ -10,3 +16,94 @@ func MustDefaultGithubEndpoint() {
10
16
panic ("Default GitHub endpoint name mismatch" )
11
17
}
12
18
}
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
+ }
0 commit comments