Skip to content

Commit

Permalink
broker: Test refreshing of groups (#225)
Browse files Browse the repository at this point in the history
UDENG-4919
  • Loading branch information
adombeck authored Nov 19, 2024
2 parents 2358541 + c9b9239 commit 8c6c10d
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 181 deletions.
30 changes: 15 additions & 15 deletions cmd/authd-oidc/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/ubuntu/authd-oidc-brokers/internal/testutils"
)

var providerURL string
var issuerURL string

func TestHelp(t *testing.T) {
a := daemon.NewForTests(t, nil, providerURL, "--help")
a := daemon.NewForTests(t, nil, issuerURL, "--help")

getStdout := captureStdout(t)

Expand All @@ -29,7 +29,7 @@ func TestHelp(t *testing.T) {
}

func TestCompletion(t *testing.T) {
a := daemon.NewForTests(t, nil, providerURL, "completion", "bash")
a := daemon.NewForTests(t, nil, issuerURL, "completion", "bash")

getStdout := captureStdout(t)

Expand All @@ -38,7 +38,7 @@ func TestCompletion(t *testing.T) {
}

func TestVersion(t *testing.T) {
a := daemon.NewForTests(t, nil, providerURL, "version")
a := daemon.NewForTests(t, nil, issuerURL, "version")

getStdout := captureStdout(t)

Expand All @@ -55,7 +55,7 @@ func TestVersion(t *testing.T) {
}

func TestNoUsageError(t *testing.T) {
a := daemon.NewForTests(t, nil, providerURL, "completion", "bash")
a := daemon.NewForTests(t, nil, issuerURL, "completion", "bash")

getStdout := captureStdout(t)
err := a.Run()
Expand All @@ -66,7 +66,7 @@ func TestNoUsageError(t *testing.T) {
}

func TestUsageError(t *testing.T) {
a := daemon.NewForTests(t, nil, providerURL, "doesnotexist")
a := daemon.NewForTests(t, nil, issuerURL, "doesnotexist")

err := a.Run()
require.Error(t, err, "Run should return an error, stdout: %v")
Expand All @@ -93,7 +93,7 @@ func TestCanQuitTwice(t *testing.T) {
func TestAppCanQuitWithoutExecute(t *testing.T) {
t.Skipf("This test is skipped because it is flaky. There is no way to guarantee Quit has been called before run.")

a := daemon.NewForTests(t, nil, providerURL)
a := daemon.NewForTests(t, nil, issuerURL)

requireGoroutineStarted(t, a.Quit)
err := a.Run()
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestAppRunFailsOnComponentsCreationAndQuit(t *testing.T) {
},
}

a := daemon.NewForTests(t, &config, providerURL)
a := daemon.NewForTests(t, &config, issuerURL)
err := a.Run()
require.Error(t, err, "Run should return an error")
})
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestAppCanSigHupWithoutExecute(t *testing.T) {
r, w, err := os.Pipe()
require.NoError(t, err, "Setup: pipe shouldn't fail")

a := daemon.NewForTests(t, nil, providerURL)
a := daemon.NewForTests(t, nil, issuerURL)

orig := os.Stdout
os.Stdout = w
Expand All @@ -214,7 +214,7 @@ func TestAppCanSigHupWithoutExecute(t *testing.T) {
}

func TestAppGetRootCmd(t *testing.T) {
a := daemon.NewForTests(t, nil, providerURL)
a := daemon.NewForTests(t, nil, issuerURL)
require.NotNil(t, a.RootCmd(), "Returns root command")
}

Expand Down Expand Up @@ -246,8 +246,8 @@ func TestConfigHasPrecedenceOverPathsConfig(t *testing.T) {
}

overrideBrokerConfPath := filepath.Join(tmpDir, "override", "via", "config", "broker.conf")
daemon.GenerateBrokerConfig(t, overrideBrokerConfPath, providerURL)
a := daemon.NewForTests(t, &config, providerURL, "--config", overrideBrokerConfPath)
daemon.GenerateBrokerConfig(t, overrideBrokerConfPath, issuerURL)
a := daemon.NewForTests(t, &config, issuerURL, "--config", overrideBrokerConfPath)

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down Expand Up @@ -277,7 +277,7 @@ func TestAutoDetectConfig(t *testing.T) {
},
}

configPath := daemon.GenerateTestConfig(t, &config, providerURL)
configPath := daemon.GenerateTestConfig(t, &config, issuerURL)
configNextToBinaryPath := filepath.Join(filepath.Dir(os.Args[0]), t.Name()+".yaml")
err := os.Rename(configPath, configNextToBinaryPath)
require.NoError(t, err, "Could not relocate authd configuration file in the binary directory")
Expand Down Expand Up @@ -343,7 +343,7 @@ func requireGoroutineStarted(t *testing.T, f func()) {
func startDaemon(t *testing.T, conf *daemon.DaemonConfig) (app *daemon.App, done func()) {
t.Helper()

a := daemon.NewForTests(t, conf, providerURL)
a := daemon.NewForTests(t, conf, issuerURL)

wg := sync.WaitGroup{}
wg.Add(1)
Expand Down Expand Up @@ -402,7 +402,7 @@ func TestMain(m *testing.M) {
defer cleanup()

// Start provider mock
providerURL, cleanup = testutils.StartMockProviderServer("", nil)
issuerURL, cleanup = testutils.StartMockProviderServer("", nil)
defer cleanup()

m.Run()
Expand Down
Loading

0 comments on commit 8c6c10d

Please sign in to comment.