Exemplo n.º 1
0
func TestReadConfigFile(t *testing.T) {
	for _, ld := range loginData {

		tmpfile := test.CreateTmpConfigFile(ld.in)
		defer os.Remove(tmpfile) // clean up

		var logins loginMapping
		if err := readConfigFile(&logins, tmpfile); err != nil {
			t.Errorf("readConfigFile(&logins,%q) failed => %v", tmpfile, err)
		}

		if l := len(logins); l != ld.out {
			t.Errorf("readConfigFile(&logins,%q) => %v logins, want %v", tmpfile, l, ld.out)
		}
	}
}
Exemplo n.º 2
0
func TestWriteConfigFile(t *testing.T) {
	logins := loginMapping{}
	logins["docker.io"] = Login{Username: "******", Password: "******"}
	tmpfile := test.CreateTmpConfigFile("")
	defer os.Remove(tmpfile) // clean up

	if err := writeConfigFile(logins, tmpfile); err != nil {
		t.Errorf("writeConfigFile(logins,%q) failed => %v", tmpfile, err)
	}

	logins = loginMapping{}
	if err := readConfigFile(&logins, tmpfile); err != nil {
		t.Errorf("after writing: readConfigFile(&logins,%q) failed => %v", tmpfile, err)
	}

	if l := len(logins); l != 1 {
		t.Errorf("after writing: readConfigFile(&logins,%q) => %v logins, want %v", tmpfile, l, 1)
	}
}