2018-05-12 04:42:46 +00:00
|
|
|
package finder
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent"
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-06-26 21:59:15 +00:00
|
|
|
func TestIDFromArgs(t *testing.T) {
|
2018-05-12 04:42:46 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-03-31 19:59:56 +00:00
|
|
|
a := agent.NewTestAgent(t, ``)
|
2018-05-12 04:42:46 +00:00
|
|
|
defer a.Shutdown()
|
|
|
|
client := a.Client()
|
|
|
|
|
|
|
|
// Create a set of intentions
|
|
|
|
var ids []string
|
|
|
|
{
|
|
|
|
insert := [][]string{
|
2020-06-26 21:59:15 +00:00
|
|
|
{"a", "b"},
|
2018-05-12 04:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range insert {
|
|
|
|
ixn := &api.Intention{
|
2020-06-26 21:59:15 +00:00
|
|
|
SourceName: v[0],
|
|
|
|
DestinationName: v[1],
|
2018-05-12 04:42:46 +00:00
|
|
|
Action: api.IntentionActionAllow,
|
|
|
|
}
|
|
|
|
|
|
|
|
id, _, err := client.Connect().IntentionCreate(ixn, nil)
|
2020-06-26 21:59:15 +00:00
|
|
|
require.NoError(t, err)
|
2018-05-12 04:42:46 +00:00
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 21:59:15 +00:00
|
|
|
id, err := IDFromArgs(client, []string{"a", "b"})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, ids[0], id)
|
2018-05-12 04:42:46 +00:00
|
|
|
|
2020-06-26 21:59:15 +00:00
|
|
|
_, err = IDFromArgs(client, []string{"c", "d"})
|
|
|
|
require.Error(t, err)
|
2018-05-12 04:42:46 +00:00
|
|
|
}
|