|
|
|
@ -70,3 +70,55 @@ func TestKVImportCommand(t *testing.T) {
|
|
|
|
|
t.Fatalf("bad: expected: baz, got %s", pair.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestKVImportPrefixCommand(t *testing.T) {
|
|
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Parallel()
|
|
|
|
|
a := agent.NewTestAgent(t, ``)
|
|
|
|
|
defer a.Shutdown()
|
|
|
|
|
client := a.Client()
|
|
|
|
|
|
|
|
|
|
const json = `[
|
|
|
|
|
{
|
|
|
|
|
"key": "foo",
|
|
|
|
|
"flags": 0,
|
|
|
|
|
"value": "YmFyCg=="
|
|
|
|
|
}
|
|
|
|
|
]`
|
|
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
c := New(ui)
|
|
|
|
|
c.testStdin = strings.NewReader(json)
|
|
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
|
"-prefix=" + "sub/",
|
|
|
|
|
"-",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pair, _, err := client.KV().Get("foo", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if pair != nil {
|
|
|
|
|
t.Fatalf("bad: expected: nil, got %+v", pair)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pair, _, err = client.KV().Get("sub/foo", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if strings.TrimSpace(string(pair.Value)) != "bar" {
|
|
|
|
|
t.Fatalf("bad: expected: bar, got %s", pair.Value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|