Skip to content

Commit d8e431d

Browse files
committed
Minor broker refactorings (#224)
2 parents 5f24f7e + 1e02fbc commit d8e431d

11 files changed

Lines changed: 184 additions & 196 deletions

File tree

authd-oidc-brokers/cmd/authd-oidc/daemon/daemon_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"net/http/httptest"
87
"os"
98
"path/filepath"
109
"strings"
@@ -18,10 +17,10 @@ import (
1817
"github.com/ubuntu/authd-oidc-brokers/internal/testutils"
1918
)
2019

21-
var mockProvider *httptest.Server
20+
var providerURL string
2221

2322
func TestHelp(t *testing.T) {
24-
a := daemon.NewForTests(t, nil, mockProvider.URL, "--help")
23+
a := daemon.NewForTests(t, nil, providerURL, "--help")
2524

2625
getStdout := captureStdout(t)
2726

@@ -30,7 +29,7 @@ func TestHelp(t *testing.T) {
3029
}
3130

3231
func TestCompletion(t *testing.T) {
33-
a := daemon.NewForTests(t, nil, mockProvider.URL, "completion", "bash")
32+
a := daemon.NewForTests(t, nil, providerURL, "completion", "bash")
3433

3534
getStdout := captureStdout(t)
3635

@@ -39,7 +38,7 @@ func TestCompletion(t *testing.T) {
3938
}
4039

4140
func TestVersion(t *testing.T) {
42-
a := daemon.NewForTests(t, nil, mockProvider.URL, "version")
41+
a := daemon.NewForTests(t, nil, providerURL, "version")
4342

4443
getStdout := captureStdout(t)
4544

@@ -56,7 +55,7 @@ func TestVersion(t *testing.T) {
5655
}
5756

5857
func TestNoUsageError(t *testing.T) {
59-
a := daemon.NewForTests(t, nil, mockProvider.URL, "completion", "bash")
58+
a := daemon.NewForTests(t, nil, providerURL, "completion", "bash")
6059

6160
getStdout := captureStdout(t)
6261
err := a.Run()
@@ -67,7 +66,7 @@ func TestNoUsageError(t *testing.T) {
6766
}
6867

6968
func TestUsageError(t *testing.T) {
70-
a := daemon.NewForTests(t, nil, mockProvider.URL, "doesnotexist")
69+
a := daemon.NewForTests(t, nil, providerURL, "doesnotexist")
7170

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

97-
a := daemon.NewForTests(t, nil, mockProvider.URL)
96+
a := daemon.NewForTests(t, nil, providerURL)
9897

9998
requireGoroutineStarted(t, a.Quit)
10099
err := a.Run()
@@ -142,7 +141,7 @@ func TestAppRunFailsOnComponentsCreationAndQuit(t *testing.T) {
142141
},
143142
}
144143

145-
a := daemon.NewForTests(t, &config, mockProvider.URL)
144+
a := daemon.NewForTests(t, &config, providerURL)
146145
err := a.Run()
147146
require.Error(t, err, "Run should return an error")
148147
})
@@ -198,7 +197,7 @@ func TestAppCanSigHupWithoutExecute(t *testing.T) {
198197
r, w, err := os.Pipe()
199198
require.NoError(t, err, "Setup: pipe shouldn't fail")
200199

201-
a := daemon.NewForTests(t, nil, mockProvider.URL)
200+
a := daemon.NewForTests(t, nil, providerURL)
202201

203202
orig := os.Stdout
204203
os.Stdout = w
@@ -215,7 +214,7 @@ func TestAppCanSigHupWithoutExecute(t *testing.T) {
215214
}
216215

217216
func TestAppGetRootCmd(t *testing.T) {
218-
a := daemon.NewForTests(t, nil, mockProvider.URL)
217+
a := daemon.NewForTests(t, nil, providerURL)
219218
require.NotNil(t, a.RootCmd(), "Returns root command")
220219
}
221220

@@ -247,8 +246,8 @@ func TestConfigHasPrecedenceOverPathsConfig(t *testing.T) {
247246
}
248247

249248
overrideBrokerConfPath := filepath.Join(tmpDir, "override", "via", "config", "broker.conf")
250-
daemon.GenerateBrokerConfig(t, overrideBrokerConfPath, mockProvider.URL)
251-
a := daemon.NewForTests(t, &config, mockProvider.URL, "--config", overrideBrokerConfPath)
249+
daemon.GenerateBrokerConfig(t, overrideBrokerConfPath, providerURL)
250+
a := daemon.NewForTests(t, &config, providerURL, "--config", overrideBrokerConfPath)
252251

253252
wg := sync.WaitGroup{}
254253
wg.Add(1)
@@ -278,7 +277,7 @@ func TestAutoDetectConfig(t *testing.T) {
278277
},
279278
}
280279

281-
configPath := daemon.GenerateTestConfig(t, &config, mockProvider.URL)
280+
configPath := daemon.GenerateTestConfig(t, &config, providerURL)
282281
configNextToBinaryPath := filepath.Join(filepath.Dir(os.Args[0]), t.Name()+".yaml")
283282
err := os.Rename(configPath, configNextToBinaryPath)
284283
require.NoError(t, err, "Could not relocate authd configuration file in the binary directory")
@@ -344,7 +343,7 @@ func requireGoroutineStarted(t *testing.T, f func()) {
344343
func startDaemon(t *testing.T, conf *daemon.DaemonConfig) (app *daemon.App, done func()) {
345344
t.Helper()
346345

347-
a := daemon.NewForTests(t, conf, mockProvider.URL)
346+
a := daemon.NewForTests(t, conf, providerURL)
348347

349348
wg := sync.WaitGroup{}
350349
wg.Add(1)
@@ -403,9 +402,8 @@ func TestMain(m *testing.M) {
403402
defer cleanup()
404403

405404
// Start provider mock
406-
providerServer, cleanup := testutils.StartMockProvider("", nil)
405+
providerURL, cleanup = testutils.StartMockProviderServer("", nil)
407406
defer cleanup()
408-
mockProvider = providerServer
409407

410408
m.Run()
411409
}

0 commit comments

Comments
 (0)