@@ -110,22 +110,44 @@ func TestPodmanConfig(t *testing.T) {
110
110
111
111
os .Unsetenv ("DOCKER_CONFIG" )
112
112
// At first, $DOCKER_CONFIG is unset and $HOME/.docker/config.json isn't
113
- // found, but Podman auth $XDG_RUNTIME_DIR/containers/auth.json is configured.
114
- // This should return Podman's auth $XDG_RUNTIME_DIR/containers/auth.json.
113
+ // found. $XDG_RUNTIME_DIR is unset too to simulate macOS/Windows environment
114
+ // This should return Podman's auth $HOME/.config/containers/auth.json.
115
+ writeConfig (t , filepath .Join (os .Getenv ("HOME" ), ".config" , "containers" ), "auth.json" ,
116
+ fmt .Sprintf (`{"auths": {"test.io": {"auth": %q}}}` ,
117
+ encode ("DEFAULT-MAC-WIN-foo" , "DEFAULT-MAC-WIN-bar" )))
118
+ defer func () { os .Remove (filepath .Join (os .Getenv ("HOME" ), ".config/containers/auth.json" )) }()
119
+ auth , err := DefaultKeychain .Resolve (testRegistry )
120
+ if err != nil {
121
+ t .Fatalf ("Resolve() = %v" , err )
122
+ }
123
+ got , err := auth .Authorization ()
124
+ if err != nil {
125
+ t .Fatal (err )
126
+ }
127
+ want := & AuthConfig {
128
+ Username : "DEFAULT-MAC-WIN-foo" ,
129
+ Password : "DEFAULT-MAC-WIN-bar" ,
130
+ }
131
+ if ! reflect .DeepEqual (got , want ) {
132
+ t .Errorf ("got %+v, want %+v" , got , want )
133
+ }
134
+
135
+ // Then, XDG_RUNTIME_DIR is populated, to simulate a Linux environment,
136
+ // and Podman auth $XDG_RUNTIME_DIR/containers/auth.json is configured.
115
137
p := filepath .Join (tmpdir , fmt .Sprintf ("%d" , fresh ))
116
138
t .Setenv ("XDG_RUNTIME_DIR" , p )
117
139
writeConfig (t , filepath .Join (p , "containers" ), "auth.json" ,
118
140
fmt .Sprintf (`{"auths": {"test.io": {"auth": %q}}}` ,
119
141
encode ("XDG_RUNTIME_DIR-foo" , "XDG_RUNTIME_DIR-bar" )))
120
- auth , err : = DefaultKeychain .Resolve (testRegistry )
142
+ auth , err = DefaultKeychain .Resolve (testRegistry )
121
143
if err != nil {
122
144
t .Fatalf ("Resolve() = %v" , err )
123
145
}
124
- got , err : = auth .Authorization ()
146
+ got , err = auth .Authorization ()
125
147
if err != nil {
126
148
t .Fatal (err )
127
149
}
128
- want : = & AuthConfig {
150
+ want = & AuthConfig {
129
151
Username : "XDG_RUNTIME_DIR-foo" ,
130
152
Password : "XDG_RUNTIME_DIR-bar" ,
131
153
}
0 commit comments