Skip to content

Commit

Permalink
Add github endpoint operations e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
  • Loading branch information
gabriel-samfira committed Apr 24, 2024
1 parent 1256473 commit ccf5105
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
echo "GARM_PASSWORD=$GARM_PASSWORD" >> $GITHUB_ENV
echo "REPO_WEBHOOK_SECRET=$REPO_WEBHOOK_SECRET" >> $GITHUB_ENV
echo "ORG_WEBHOOK_SECRET=$ORG_WEBHOOK_SECRET" >> $GITHUB_ENV
echo "GARM_CHECKOUT_DIR=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Create logs directory
if: always()
Expand Down
102 changes: 102 additions & 0 deletions test/integration/e2e/endpoints.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package e2e

import (
"os"
"path/filepath"

"github.com/cloudbase/garm/params"
)

func MustDefaultGithubEndpoint() {
ep := GetGithubEndpoint("github.com")
if ep == nil {
Expand All @@ -10,3 +17,98 @@ func MustDefaultGithubEndpoint() {
panic("Default GitHub endpoint name mismatch")
}
}

func checkEndpointParamsAreEqual(a, b params.GithubEndpoint) {
if a.Name != b.Name {
panic("Endpoint name mismatch")
}

if a.Description != b.Description {
panic("Endpoint description mismatch")
}

if a.BaseURL != b.BaseURL {
panic("Endpoint base URL mismatch")
}

if a.APIBaseURL != b.APIBaseURL {
panic("Endpoint API base URL mismatch")
}

if a.UploadBaseURL != b.UploadBaseURL {
panic("Endpoint upload base URL mismatch")
}

if string(a.CACertBundle) != string(b.CACertBundle) {
panic("Endpoint CA cert bundle mismatch")
}
}

func TestGithubEndpointOperations() {
baseDir := os.Getenv("GARM_CHECKOUT_DIR")
if baseDir == "" {
panic("GARM_CHECKOUT_DIR not set")
}
caBundle, err := os.ReadFile(filepath.Join(baseDir, "testdata/certs/srv-pub.pem"))
if err != nil {
panic(err)
}
endpointParams := params.CreateGithubEndpointParams{
Name: "test-endpoint",
Description: "Test endpoint",
BaseURL: "https://ghes.example.com",
APIBaseURL: "https://api.ghes.example.com/",
UploadBaseURL: "https://uploads.ghes.example.com/",
CACertBundle: caBundle,
}

endpoint := CreateGithubEndpoint(endpointParams)
if endpoint.Name != endpointParams.Name {
panic("Endpoint name mismatch")
}

if endpoint.Description != endpointParams.Description {
panic("Endpoint description mismatch")
}

if endpoint.BaseURL != endpointParams.BaseURL {
panic("Endpoint base URL mismatch")
}

if endpoint.APIBaseURL != endpointParams.APIBaseURL {
panic("Endpoint API base URL mismatch")
}

if endpoint.UploadBaseURL != endpointParams.UploadBaseURL {
panic("Endpoint upload base URL mismatch")
}

if string(endpoint.CACertBundle) != string(caBundle) {
panic("Endpoint CA cert bundle mismatch")
}

endpoint2 := GetGithubEndpoint(endpointParams.Name)
if endpoint == nil || endpoint2 == nil {
panic("endpoint is nil")
}
checkEndpointParamsAreEqual(*endpoint, *endpoint2)

endpoints := ListGithubEndpoints()
var found bool
for _, ep := range endpoints {
if ep.Name == endpointParams.Name {
checkEndpointParamsAreEqual(*endpoint, ep)
found = true
break
}
}
if !found {
panic("Endpoint not found in list")
}

DeleteGithubEndpoint(endpoint.Name)

if err := deleteGithubEndpoint(cli, authToken, "github.com"); err == nil {
panic("expected error when attempting to delete the default github.com endpoint")
}
}
3 changes: 3 additions & 0 deletions test/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func main() {
// Create test credentials
e2e.EnsureTestCredentials(credentialsName, ghToken, "github.com")

// Test endpoint operations
e2e.TestGithubEndpointOperations()

// //////////////////
// controller info //
// //////////////////
Expand Down

0 comments on commit ccf5105

Please sign in to comment.