Пример #1
0
func TestKenvDump(t *testing.T) {
	fromCmd := kenvsFromCmd(t)

	kenvs, err := kenv.Dump()
	if err != nil {
		t.Error(err)
	}

	var fromLib []string
	for _, item := range kenvs {
		keyval := strings.Split(item, "=")
		if len(keyval) != 2 {
			t.Errorf("%s has different format than key=val", keyval)
		}
		fromLib = append(fromLib, fmt.Sprintf("%s=\"%s\"", keyval[0], keyval[1]))
	}

	if len(fromLib) != len(fromCmd) {
		t.Errorf("cmd has %d item but lib has %d", len(fromCmd), len(fromLib))
	}

	for i, ke := range fromCmd {
		if fromLib[i] != ke {
			t.Errorf("lib %s different than %s", fromLib[i], ke)
		}
	}
}
Пример #2
0
func dump() error {
	kenvs, err := kenv.Dump()
	if err != nil {
		return fmt.Errorf("Unable to dump kenv: %v", err)
	}

	for _, item := range kenvs {
		if *hflag {
			if !strings.HasPrefix(item, "hint.") {
				continue
			}
		}

		keyval := strings.Split(item, "=")
		if len(keyval) != 2 {
			continue
		}

		if *Nflag {
			fmt.Printf("%s\n", keyval[0])
		} else {
			fmt.Printf("%s=\"%s\"\n", keyval[0], keyval[1])
		}
	}
	return nil
}