Example #1
0
func genv(g *libkb.GlobalContext) {
	g.Env.GetConfig()
	g.Env.GetConfigWriter()
	g.Env.GetCommandLine()
	g.Env.SetConfig(libkb.NewJSONConfigFile(g, ""))
	g.Env.SetConfigWriter(libkb.NewJSONConfigFile(g, ""))
}
Example #2
0
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)
	}
}
Example #3
0
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)
	}
}
Example #4
0
func TestSetStringInExisting(t *testing.T) {
	config := &libkb.TestConfig{}
	config.InitTest(t, `{ "aaa": { "xxx": "yyy"} }`)
	defer config.CleanTest()

	checker := func(cf libkb.JSONConfigFile, key string) {
		if ret, isSet := cf.GetStringAtPath(key); !isSet || ret != "blah" {
			t.Errorf("Couldn't read string after setting; ret=%s, isSet=%t",
				ret, isSet)
		}
	}

	setAndCheck(t, config, "aaa.bbb.ccc", "blah", checker)
	// and make sure the existing key is still there
	cf := libkb.NewJSONConfigFile(G, config.GetConfigFileName())
	if err := cf.Load(false); err != nil {
		t.Fatalf("Couldn't load config file %s", config.GetConfigFileName())
	}
	if ret, isSet := cf.GetStringAtPath("aaa.xxx"); !isSet || ret != "yyy" {
		t.Errorf("Couldn't read old string after setting; ret=%s, isSet=%t",
			ret, isSet)
	}
}