Skip to content

Commit

Permalink
Code review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
  • Loading branch information
naveensrinivasan committed Jun 21, 2023
1 parent 30bd512 commit a9d337e
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions clients/githubrepo/roundtripper/tokens/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,11 @@ func TestMakeTokenAccessor(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
switch {
case tt.useGitHubToken:
token := "test"
t.Setenv("GITHUB_TOKEN", token)
got := MakeTokenAccessor()
if got == nil {
t.Errorf("MakeTokenAccessor() = nil, want not nil")
}
raccess, ok := got.(*roundRobinAccessor)
if !ok {
t.Errorf("MakeTokenAccessor() = %v, want *roundRobinAccessor", got)
}
if raccess.accessTokens[0] != token {
t.Errorf("accessTokens[0] = %v, want %v", raccess.accessTokens[0], token)
}
t.Helper()
testToken(t)
case tt.useServer:
t.Setenv("GITHUB_AUTH_SERVER", "localhost:8080")
server := startTestServer()
defer serverShutdown(server)
myRPCService := &MyRPCService{}
rpc.Register(myRPCService) //nolint:errcheck
server.Handler = nil
rpc.HandleHTTP()
got := MakeTokenAccessor()
if got == nil {
t.Errorf("MakeTokenAccessor() = nil, want not nil")
}
t.Helper()
testServer(t)
default:
got := MakeTokenAccessor()
if got != nil {
Expand All @@ -81,15 +61,48 @@ func TestMakeTokenAccessor(t *testing.T) {
}
}

func testToken(t *testing.T) {

Check failure on line 64 in clients/githubrepo/roundtripper/tokens/accessor_test.go

View workflow job for this annotation

GitHub Actions / check-linter

test helper function should start from t.Helper() (thelper)
t.Setenv("GITHUB_TOKEN", "")
token := "test"
t.Setenv("GITHUB_TOKEN", token)
got := MakeTokenAccessor()
if got == nil {
t.Errorf("MakeTokenAccessor() = nil, want not nil")
}
raccess, ok := got.(*roundRobinAccessor)
if !ok {
t.Errorf("MakeTokenAccessor() = %v, want *roundRobinAccessor", got)
}
if raccess.accessTokens[0] != token {
t.Errorf("accessTokens[0] = %v, want %v", raccess.accessTokens[0], token)
}
}

func testServer(t *testing.T) {

Check failure on line 81 in clients/githubrepo/roundtripper/tokens/accessor_test.go

View workflow job for this annotation

GitHub Actions / check-linter

test helper function should start from t.Helper() (thelper)
t.Setenv("GITHUB_AUTH_SERVER", "localhost:8080")
server := startTestServer()
t.Cleanup(func() {
serverShutdown(server)
})
myRPCService := &MyRPCService{}
rpc.Register(myRPCService) //nolint:errcheck
server.Handler = nil
rpc.HandleHTTP()
got := MakeTokenAccessor()
if got == nil {
t.Errorf("MakeTokenAccessor() = nil, want not nil")
}
}

type MyRPCService struct {
// Define your RPC service methods here
}

func startTestServer() *http.Server {
// Create a new server
server := &http.Server{ //nolint:gosec
Addr: ":8080", // Use any available port
Handler: nil, // Use the default handler
Addr: ":8080",
Handler: nil, // Use the default handler
}

// Start the server in a separate goroutine
Expand Down

0 comments on commit a9d337e

Please sign in to comment.