MCPcopy Index your code
hub / github.com/devspace-sh/devspace / TestLogin

Function TestLogin

pkg/devspace/docker/auth_test.go:211–285  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

209}
210
211func TestLogin(t *testing.T) {
212 testCases := []loginTestCase{
213 {
214 name: "Use default server",
215 checkCredentialsStore: true,
216 saveAuthConfig: true,
217 user: "user",
218 password: "useToken",
219 expectedAuthConfig: &dockerregistry.AuthConfig{
220 ServerAddress: "IndexServerAddress",
221 Username: "user",
222 IdentityToken: "someToken",
223 },
224 },
225 }
226
227 dir := t.TempDir()
228
229 wdBackup, err := os.Getwd()
230 if err != nil {
231 t.Fatalf("Error getting current working directory: %v", err)
232 }
233 err = os.Chdir(dir)
234 if err != nil {
235 t.Fatalf("Error changing working directory: %v", err)
236 }
237 dir, err = filepath.EvalSymlinks(dir)
238 if err != nil {
239 t.Fatal(err)
240 }
241
242 defer func() {
243 err = os.Chdir(wdBackup)
244 if err != nil {
245 t.Fatalf("Error changing dir back: %v", err)
246 }
247 }()
248
249 configDir = dir
250
251 for _, testCase := range testCases {
252 for path, content := range testCase.files {
253 asJSON, err := json.Marshal(content)
254 assert.NilError(t, err, "Error parsing content to json in testCase %s", testCase.name)
255 if content == "" {
256 asJSON = []byte{}
257 }
258 err = fsutil.WriteToFile(asJSON, path)
259 assert.NilError(t, err, "Error writing file in testCase %s", testCase.name)
260 }
261
262 client := &client{
263 APIClient: &fakeDockerClient{},
264 }
265
266 auth, err := client.Login(context.Background(), testCase.registryURL, testCase.user, testCase.password, testCase.checkCredentialsStore, testCase.saveAuthConfig, testCase.relogin)
267 if !testCase.expectedErr {
268 assert.NilError(t, err, "Unexpected error in testCase %s", testCase.name)

Callers

nothing calls this directly

Calls 5

LoginMethod · 0.95
WriteToFileFunction · 0.92
EqualMethod · 0.80
FatalfMethod · 0.45
FatalMethod · 0.45

Tested by

no test coverage detected