Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions cli/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,6 @@ func TestServer(t *testing.T) {
createUserPostRestart bool
}

waitAuthMethods := func(t *testing.T, ctx context.Context, client *codersdk.Client, expected codersdk.GithubAuthMethod) codersdk.AuthMethods {
t.Helper()

var authMethods codersdk.AuthMethods
testutil.Eventually(ctx, t, func(ctx context.Context) bool {
var err error
authMethods, err = client.AuthMethods(ctx)
return err == nil && authMethods.Github == expected
}, testutil.IntervalFast, "github auth method did not reach expected state: %+v", expected)
return authMethods
}

runGitHubProviderTest := func(t *testing.T, tc testCase) {
t.Parallel()

Expand All @@ -426,7 +414,8 @@ func TestServer(t *testing.T) {
args := []string{
"server",
"--postgres-url", dbURL,
"--http-address", ":0",
// Match the client's loopback address to avoid overlapping wildcard listeners on macOS.
"--http-address", "127.0.0.1:0",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only new change in this PR. The rest is reverting previous PRs that introduced ineffective fixes.

"--access-url", "https://example.com",
}
if tc.githubClientID != "" {
Expand Down Expand Up @@ -463,12 +452,11 @@ func TestServer(t *testing.T) {
}

client := codersdk.New(accessURL)
expectedGithubAuthMethod := codersdk.GithubAuthMethod{
Enabled: tc.expectGithubEnabled,
DefaultProviderConfigured: tc.expectGithubDefaultProviderConfigured,
}
authMethods := waitAuthMethods(t, ctx, client, expectedGithubAuthMethod)
require.Equal(t, expectedGithubAuthMethod, authMethods.Github)

authMethods, err := client.AuthMethods(ctx)
require.NoError(t, err)
require.Equal(t, tc.expectGithubEnabled, authMethods.Github.Enabled)
require.Equal(t, tc.expectGithubDefaultProviderConfigured, authMethods.Github.DefaultProviderConfigured)

cancelFunc()
select {
Expand All @@ -489,8 +477,10 @@ func TestServer(t *testing.T) {
client = codersdk.New(accessURL)

ctx = testutil.Context(t, testutil.WaitLong)
authMethods = waitAuthMethods(t, ctx, client, expectedGithubAuthMethod)
require.Equal(t, expectedGithubAuthMethod, authMethods.Github)
authMethods, err = client.AuthMethods(ctx)
require.NoError(t, err)
require.Equal(t, tc.expectGithubEnabled, authMethods.Github.Enabled)
require.Equal(t, tc.expectGithubDefaultProviderConfigured, authMethods.Github.DefaultProviderConfigured)
}

for _, tc := range []testCase{
Expand Down
Loading