summaryrefslogtreecommitdiff
path: root/internal/command
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2022-11-28 11:46:25 +0800
committerPatrick Bajao <ebajao@gitlab.com>2022-11-28 11:53:26 +0800
commitb42774409ff6780f4d5d335f732a60b807d61efa (patch)
tree0090a036ba3a72f033d66fd3fe2afc9f2c6bbb7a /internal/command
parent75f184619640e1cd2fc820091064644df9b05279 (diff)
downloadgitlab-shell-b42774409ff6780f4d5d335f732a60b807d61efa.tar.gz
Use blocking reader to fix race in test
The `TestCanceledContext` test in `twofactorverify_test.go` tests the scenario wherein the request context gets canceled in the middle of the request. A race can occur though when the input gets read before the context is canceled which can result to a different error: instead of having the context canceled, the OTP will be blank. To fix it, we use a blocking reader as input to simulate "waiting for input" scenario. This way, reading the input will never be finished and the context cancelation can be done appropriately.
Diffstat (limited to 'internal/command')
-rw-r--r--internal/command/twofactorverify/twofactorverify_test.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/internal/command/twofactorverify/twofactorverify_test.go b/internal/command/twofactorverify/twofactorverify_test.go
index fcc095f..640d3ed 100644
--- a/internal/command/twofactorverify/twofactorverify_test.go
+++ b/internal/command/twofactorverify/twofactorverify_test.go
@@ -177,7 +177,7 @@ func TestCanceledContext(t *testing.T) {
cmd := &Command{
Config: &config.Config{GitlabUrl: url},
Args: &commandargs.Shell{GitlabKeyId: "wait_infinitely"},
- ReadWriter: &readwriter.ReadWriter{Out: output, In: &bytes.Buffer{}},
+ ReadWriter: &readwriter.ReadWriter{Out: output, In: &blockingReader{}},
}
ctx, cancel := context.WithCancel(context.Background())