Skip to content

Commit f5b6055

Browse files
committed
cli/command/registry: add unit test for --password-stdin
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent b82e30e commit f5b6055

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cli/command/registry/login_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package registry
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
@@ -92,6 +93,7 @@ func TestRunLogin(t *testing.T) {
9293
testCases := []struct {
9394
doc string
9495
priorCredentials map[string]configtypes.AuthConfig
96+
stdIn string
9597
input loginOptions
9698
expectedCredentials map[string]configtypes.AuthConfig
9799
expectedErr string
@@ -287,6 +289,23 @@ func TestRunLogin(t *testing.T) {
287289
},
288290
},
289291
},
292+
{
293+
doc: "password stdin with line-endings",
294+
priorCredentials: map[string]configtypes.AuthConfig{},
295+
stdIn: "my password\r\n",
296+
input: loginOptions{
297+
serverAddress: "reg1",
298+
user: "my-username",
299+
passwordStdin: true,
300+
},
301+
expectedCredentials: map[string]configtypes.AuthConfig{
302+
"reg1": {
303+
Username: "my-username",
304+
Password: "my password",
305+
ServerAddress: "reg1",
306+
},
307+
},
308+
},
290309
}
291310

292311
for _, tc := range testCases {
@@ -295,6 +314,9 @@ func TestRunLogin(t *testing.T) {
295314
cfg := configfile.New(filepath.Join(tmpDir, "config.json"))
296315
cli := test.NewFakeCli(&fakeClient{})
297316
cli.SetConfigFile(cfg)
317+
if tc.input.passwordStdin {
318+
cli.SetIn(streams.NewIn(io.NopCloser(bytes.NewBufferString(tc.stdIn))))
319+
}
298320

299321
for _, priorCred := range tc.priorCredentials {
300322
assert.NilError(t, cfg.GetCredentialsStore(priorCred.ServerAddress).Store(priorCred))

0 commit comments

Comments
 (0)