Skip to content

Commit 0fc1169

Browse files
committed
Add regression test for authConfig overwrite
1 parent 9332c00 commit 0fc1169

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

auth/auth_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package auth
33
import (
44
"crypto/rand"
55
"encoding/hex"
6+
"io/ioutil"
67
"os"
78
"strings"
89
"testing"
@@ -51,7 +52,7 @@ func TestCreateAccount(t *testing.T) {
5152
}
5253
token := hex.EncodeToString(tokenBuffer)[:12]
5354
username := "ut" + token
54-
authConfig := &AuthConfig{Username: username, Password: "test42", Email: "docker-ut+"+token+"@example.com"}
55+
authConfig := &AuthConfig{Username: username, Password: "test42", Email: "docker-ut+" + token + "@example.com"}
5556
status, err := Login(authConfig)
5657
if err != nil {
5758
t.Fatal(err)
@@ -73,3 +74,39 @@ func TestCreateAccount(t *testing.T) {
7374
t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err)
7475
}
7576
}
77+
78+
func TestSameAuthDataPostSave(t *testing.T) {
79+
root, err := ioutil.TempDir("", "docker-test")
80+
if err != nil {
81+
t.Fatal(err)
82+
}
83+
configFile := &ConfigFile{
84+
rootPath: root,
85+
Configs: make(map[string]AuthConfig, 1),
86+
}
87+
88+
configFile.Configs["testIndex"] = AuthConfig{
89+
Username: "docker-user",
90+
Password: "docker-pass",
91+
92+
}
93+
94+
err = SaveConfig(configFile)
95+
if err != nil {
96+
t.Fatal(err)
97+
}
98+
99+
authConfig := configFile.Configs["testIndex"]
100+
if authConfig.Username != "docker-user" {
101+
t.Fail()
102+
}
103+
if authConfig.Password != "docker-pass" {
104+
t.Fail()
105+
}
106+
if authConfig.Email != "[email protected]" {
107+
t.Fail()
108+
}
109+
if authConfig.Auth != "" {
110+
t.Fail()
111+
}
112+
}

0 commit comments

Comments
 (0)