Skip to content

GitHub SCM Plugin: Test Failure - Token Validation Mismatch #7643

@josill

Description

@josill

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The test case TestNew/No_Error_for_missing_token expects that creating a GitHub client without a token should not return an error (wantErr: false), but it currently fails with:

--- FAIL: TestNew (0.28s)
    --- FAIL: TestNew/No_Error_for_missing_token (0.00s)
        main_test.go:261: 
            	Error Trace:	/Users/josill/Desktop/Projects/updatecli/pkg/plugins/scms/github/main_test.go:261
            	Error:      	Received unexpected error:
            	            	creating GitHub client: github token is not set
            	Test:       	TestNew/No_Error_for_missing_token

Code Location:

  • pkg/plugins/scms/github/main_test.go:230-251 - Test case definition
  • pkg/plugins/scms/github/client/main.go:72-77 - Token validation logic that returns error

Expected Behavior

The test No_Error_for_missing_token expects that New() should succeed even without a token. However, the current implementation requires a token to create a GitHub client.

There are two possible resolutions:

Option A: The test expectation is incorrect and should be updated to match current behavior:

  • Change wantErr: false to wantErr: true for the "No Error for missing token" test
  • Update test name to reflect that an error is expected (e.g., "Error for missing token")

Option B: The implementation should allow creating a GitHub instance without a token:

  • Modify client.New() to return a client with nil token source when no token is provided
  • Handle nil token cases in subsequent operations (may require changes throughout the codebase)
  • This would allow creating a GitHub client for read-only operations or when token is provided later

Steps To Reproduce

  1. Run the GitHub SCM plugin tests:

    cd /Users/josill/Desktop/Projects/updatecli
    go test ./pkg/plugins/scms/github -v
  2. Observe the test failure:

    • Test TestNew/No_Error_for_missing_token fails with "github token is not set" error

Environment

- **OS**: macOS (Darwin 24.6.0, ARM64) - but this issue likely affects all platforms
- **Go Version**: go1.25.5 darwin/arm64
- **Test Command**: `go test ./pkg/plugins/scms/github`

Pipeline Graph

Anything else?

I think this happens only in local environment since it isnt an error in pipeline tests...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions