コード例 #1
0
ファイル: cmd_config_test.go プロジェクト: mark-adams/client
func TestClear(t *testing.T) {
	config := &libkb.TestConfig{}
	config.InitTest(t, `{ "a": "b", "c": "d" }`)
	defer config.CleanTest()

	// clear it
	var called bool
	c := CmdConfigSet{}
	c.key = "c"
	// should be no output
	c.writer = libkb.NewTestOutput("", t, &called)
	c.Run()
	if called {
		t.Errorf("Read output for cleared key %s", c.key)
	}

	// make sure it's really done
	fn := config.GetConfigFileName()
	cf := libkb.NewJSONConfigFile(G, fn)
	if err := cf.Load(false); err != nil {
		t.Fatalf("Couldn't load config file %s", fn)
	}
	if ret, isSet := cf.GetStringAtPath("c"); isSet {
		t.Errorf("Read string after clearing; ret=%s, isSet=%t", ret, isSet)
	}
	// a should still be there
	if ret, isSet := cf.GetStringAtPath("a"); !isSet {
		t.Errorf("Couldn't read string after clearing other string; "+
			"ret=%s, isSet=%t", ret, isSet)
	}
}
コード例 #2
0
ファイル: cmd_config_test.go プロジェクト: mark-adams/client
func TestReset(t *testing.T) {
	config := &libkb.TestConfig{}
	config.InitTest(t, `{ "a": true }`)
	defer config.CleanTest()

	var called bool
	c := CmdConfigReset{}
	// no output for this test
	c.writer = libkb.NewTestOutput("", t, &called)
	c.Run()

	// Now the file should be empty
	if p, err := ioutil.ReadFile(config.GetConfigFileName()); err == nil {
		s := string(p)
		if s != "{}" {
			t.Errorf("After resetting the file, got contents: %s", s)
		}
	} else {
		t.Fatalf("Couldn't read file %s", config.GetConfigFileName())
	}

	// should be no output
	if called {
		t.Errorf("Did not reset")
	}
}
コード例 #3
0
ファイル: cmd_config_test.go プロジェクト: mark-adams/client
func checkRead(t *testing.T, key string, expected string) {
	var called bool
	c := CmdConfigGet{}
	c.key = key
	c.writer = libkb.NewTestOutput(expected, t, &called)
	c.Run()
	if !called {
		t.Errorf("Did not read %s", c.key)
	}
}
コード例 #4
0
ファイル: cmd_config_test.go プロジェクト: mark-adams/client
func TestLocation(t *testing.T) {
	config := &libkb.TestConfig{}
	config.InitTest(t, "{}")
	defer config.CleanTest()

	var called bool
	c := CmdConfigInfo{}
	c.writer = libkb.NewTestOutput("File: "+config.GetConfigFileName()+"\n\n", t, &called)
	c.Run()
	if !called {
		t.Errorf("Did not output location")
	}
}
コード例 #5
0
ファイル: cmd_config_test.go プロジェクト: mark-adams/client
func TestReadMissingVar(t *testing.T) {
	config := &libkb.TestConfig{}
	config.InitTest(t, "")
	defer config.CleanTest()

	var called bool
	c := CmdConfigGet{}
	c.key = "a"
	c.writer = libkb.NewTestOutput("", t, &called)
	c.Run()
	if called {
		t.Errorf("Expected nothing, but read %s", c.key)
	}
}
コード例 #6
0
ファイル: cmd_config_test.go プロジェクト: mark-adams/client
func setAndCheck(t *testing.T, config *libkb.TestConfig, key string, value string,
	checker func(libkb.JSONConfigFile, string)) {
	var called bool
	c := CmdConfigSet{}
	c.key = key
	c.value = value
	// should be no output
	c.writer = libkb.NewTestOutput("", t, &called)
	c.Run()

	// check the file by reading it in
	cf := libkb.NewJSONConfigFile(G, config.GetConfigFileName())
	if err := cf.Load(false); err != nil {
		t.Fatalf("Couldn't load config file %s", config.GetConfigFileName())
	}
	checker(*cf, key)

	// should be no output
	if called {
		t.Errorf("Did not read %s", c.key)
	}
}