From dac71e738c941a3c59502dcd55158d01be30530c Mon Sep 17 00:00:00 2001 From: sudoforge Date: Wed, 7 May 2025 20:30:33 -0700 Subject: [PATCH] test: simplify github-related variables (#1396) This change removes extraneous variables used for the github bridge (e2e) tests, conslidating on GITHUB_USER and GITHUB_TOKEN, which match the variables read by the github CLI and what users would have in their environment if they are using the vars. We leave GITHUB_TOKEN_PRIVATE and GITHUB_TOKEN_PUBLIC for now, as those are used in a single test to validate a minimum set of permissions. Moving away from these will require additional refactoring. Change-Id: I8d83e4f0c9b2556133c5ec3daca492fe1a4bd968 --- .github/workflows/build-and-test.yml | 4 ++-- bridge/github/export_test.go | 12 ++++++++---- bridge/github/import_test.go | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 96268ba633c0262b673c76d86f08fa2d012b2c63..cd1766870d857869c906f0468dac26d693c09cbb 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -29,8 +29,8 @@ jobs: - name: Test run: make test env: - GITHUB_TEST_USER: ${{ secrets._GITHUB_TEST_USER }} - GITHUB_TOKEN_ADMIN: ${{ secrets._GITHUB_TOKEN_ADMIN }} + GITHUB_USER: ${{ env.TEST_USER_GITHUB }} + GITHUB_TOKEN: ${{ secrets.TEST_TOKEN_GITHUB }} GITHUB_TOKEN_PRIVATE: ${{ secrets._GITHUB_TOKEN_PRIVATE }} GITHUB_TOKEN_PUBLIC: ${{ secrets._GITHUB_TOKEN_PUBLIC }} GITLAB_API_TOKEN: ${{ secrets.GITLAB_API_TOKEN }} diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index 9b10020dc101222bd1490ac97679c763e9c85af2..9d8297e4b7a937f7aa44a055f5ba30b443c976f7 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "math/rand" "net/http" "os" @@ -130,12 +131,15 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase { func TestGithubPushPull(t *testing.T) { // repo owner - envUser := os.Getenv("GITHUB_TEST_USER") + envUser := os.Getenv("GITHUB_USER") + if envUser == "" { + t.Skip("missing required environment variable: GITHUB_USER") + } // token must have 'repo' and 'delete_repo' scopes - envToken := os.Getenv("GITHUB_TOKEN_ADMIN") + envToken := os.Getenv("GITHUB_TOKEN") if envToken == "" { - t.Skip("Env var GITHUB_TOKEN_ADMIN missing") + t.Skip("missing required environment variable: GITHUB_TOKEN") } // create repo backend @@ -179,7 +183,7 @@ func TestGithubPushPull(t *testing.T) { err = createRepository(projectName, envToken) require.NoError(t, err) - fmt.Println("created repository", projectName) + slog.Info("created github repository", "name", projectName) // Let Github handle the repo creation and update all their internal caches. // Avoid HTTP error 404 retrieving repository node id diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go index 380c09a7cbf5ed3fc33bce25e491e43bb04745fa..f81df28c2e7014a8ff3c8585fe64c5591d9e6e81 100644 --- a/bridge/github/import_test.go +++ b/bridge/github/import_test.go @@ -22,9 +22,9 @@ import ( ) func TestGithubImporter(t *testing.T) { - envToken := os.Getenv("GITHUB_TOKEN_PRIVATE") + envToken := os.Getenv("GITHUB_TOKEN") if envToken == "" { - t.Skip("Env var GITHUB_TOKEN_PRIVATE missing") + t.Skip("missing required environment variable: GITHUB_TOKEN") } repo := repository.CreateGoGitTestRepo(t, false)