Example #1
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 #2
0
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")
	}
}
Example #3
0
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)
	}
}
Example #4
0
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")
	}
}
Example #5
0
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)
	}
}
Example #6
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)
	}
}