Fix flaky CLI Intention Listing Test
This commit is contained in:
parent
2d2ce1fb0c
commit
9dedfe05a2
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent"
|
"github.com/hashicorp/consul/agent"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +20,6 @@ func TestIntentionListCommand_noTabs(t *testing.T) {
|
||||||
|
|
||||||
func TestIntentionListCommand(t *testing.T) {
|
func TestIntentionListCommand(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
require := require.New(t)
|
|
||||||
a := agent.NewTestAgent(t, ``)
|
a := agent.NewTestAgent(t, ``)
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
client := a.Client()
|
client := a.Client()
|
||||||
|
@ -28,13 +28,17 @@ func TestIntentionListCommand(t *testing.T) {
|
||||||
var id string
|
var id string
|
||||||
{
|
{
|
||||||
var err error
|
var err error
|
||||||
//nolint:staticcheck
|
// This needs to be in a retry in 1.9+ due to the potential to get errors about
|
||||||
id, _, err = client.Connect().IntentionCreate(&api.Intention{
|
// intentions being read only during intention -> config entry migration.
|
||||||
SourceName: "web",
|
retry.Run(t, func(r *retry.R) {
|
||||||
DestinationName: "db",
|
//nolint:staticcheck
|
||||||
Action: api.IntentionActionAllow,
|
id, _, err = client.Connect().IntentionCreate(&api.Intention{
|
||||||
}, nil)
|
SourceName: "web",
|
||||||
require.NoError(err)
|
DestinationName: "db",
|
||||||
|
Action: api.IntentionActionAllow,
|
||||||
|
}, nil)
|
||||||
|
require.NoError(r, err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all intentions
|
// List all intentions
|
||||||
|
@ -42,6 +46,6 @@ func TestIntentionListCommand(t *testing.T) {
|
||||||
cmd := New(ui)
|
cmd := New(ui)
|
||||||
args := []string{"-http-addr=" + a.HTTPAddr()}
|
args := []string{"-http-addr=" + a.HTTPAddr()}
|
||||||
|
|
||||||
require.Equal(0, cmd.Run(args), ui.ErrorWriter.String())
|
require.Equal(t, 0, cmd.Run(args), ui.ErrorWriter.String())
|
||||||
require.Contains(ui.OutputWriter.String(), id)
|
require.Contains(t, ui.OutputWriter.String(), id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue