Esempio n. 1
0
func TestKenvGet(t *testing.T) {
	// get key and values from os commands output
	kenvs := make(map[string]string)
	for _, ke := range kenvsFromCmd(t) {
		// items in the form key="value"
		strs := strings.Split(ke, "=")
		if len(strs) != 2 {
			t.Errorf("%s", ke)
		}
		val, err := strconv.Unquote(strs[1])
		if err != nil {
			t.Error(err)
		}

		kenvs[strs[0]] = val
	}

	// for each key call kenv.Get and check value
	for k, v := range kenvs {
		get, err := kenv.Get(k)
		if err != nil {
			t.Error(err)
		}

		if get != v {
			t.Errorf("k:%q = get:%q , expected v:%q", k, get, v)
		}
	}
}
Esempio n. 2
0
func get(name string) error {
	value, err := kenv.Get(name)
	if err != nil {
		return fmt.Errorf("Unable to get %s: %v", name, err)
	}

	if *vflag {
		fmt.Printf("%s=\"%s\"", name, value)
	} else {
		fmt.Printf("%s\n", value)
	}
	return nil
}