open-consul/command/intention/list/intention_list_test.go

52 lines
1.2 KiB
Go
Raw Normal View History

package list
import (
"strings"
"testing"
"github.com/hashicorp/consul/agent"
"github.com/hashicorp/consul/api"
2021-01-19 15:31:05 +00:00
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
)
func TestIntentionListCommand_noTabs(t *testing.T) {
t.Parallel()
if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {
t.Fatal("help has tabs")
}
}
func TestIntentionListCommand(t *testing.T) {
t.Parallel()
a := agent.NewTestAgent(t, ``)
defer a.Shutdown()
client := a.Client()
// Create the intention
var id string
{
var err error
2021-01-19 15:31:05 +00:00
// This needs to be in a retry in 1.9+ due to the potential to get errors about
// intentions being read only during intention -> config entry migration.
retry.Run(t, func(r *retry.R) {
//nolint:staticcheck
id, _, err = client.Connect().IntentionCreate(&api.Intention{
SourceName: "web",
DestinationName: "db",
Action: api.IntentionActionAllow,
}, nil)
require.NoError(r, err)
})
}
// List all intentions
ui := cli.NewMockUi()
cmd := New(ui)
args := []string{"-http-addr=" + a.HTTPAddr()}
2021-01-19 15:31:05 +00:00
require.Equal(t, 0, cmd.Run(args), ui.ErrorWriter.String())
require.Contains(t, ui.OutputWriter.String(), id)
}