2019-04-30 23:27:16 +00:00
|
|
|
package delete
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent"
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigDelete_noTabs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
require.NotContains(t, New(cli.NewMockUi()).Help(), "\t")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigDelete(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2020-03-31 19:59:56 +00:00
|
|
|
a := agent.NewTestAgent(t, ``)
|
2019-04-30 23:27:16 +00:00
|
|
|
defer a.Shutdown()
|
|
|
|
client := a.Client()
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
c := New(ui)
|
|
|
|
|
|
|
|
_, _, err := client.ConfigEntries().Set(&api.ServiceConfigEntry{
|
|
|
|
Kind: api.ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "tcp",
|
|
|
|
}, nil)
|
2020-02-03 09:14:30 +00:00
|
|
|
require.NoError(t, err)
|
2019-04-30 23:27:16 +00:00
|
|
|
|
|
|
|
args := []string{
|
|
|
|
"-http-addr=" + a.HTTPAddr(),
|
|
|
|
"-kind=" + api.ServiceDefaults,
|
|
|
|
"-name=web",
|
|
|
|
}
|
|
|
|
|
|
|
|
code := c.Run(args)
|
|
|
|
require.Equal(t, 0, code)
|
|
|
|
require.Empty(t, ui.OutputWriter.String())
|
|
|
|
require.Empty(t, ui.ErrorWriter.String())
|
|
|
|
|
|
|
|
entry, _, err := client.ConfigEntries().Get(api.ServiceDefaults, "web", nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigDelete_InvalidArgs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := map[string][]string{
|
2020-06-16 17:19:31 +00:00
|
|
|
"no kind": {},
|
|
|
|
"no name": {"-kind", "service-defaults"},
|
2019-04-30 23:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, tcase := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
c := New(ui)
|
|
|
|
|
|
|
|
require.NotEqual(t, 0, c.Run(tcase))
|
|
|
|
require.NotEmpty(t, ui.ErrorWriter.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|