github.com/Iqoqo/consul@v1.4.5/command/intention/finder/finder_test.go (about)

     1  package finder
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/consul/agent"
     7  	"github.com/hashicorp/consul/api"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestFinder(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	require := require.New(t)
    15  	a := agent.NewTestAgent(t, t.Name(), ``)
    16  	defer a.Shutdown()
    17  	client := a.Client()
    18  
    19  	// Create a set of intentions
    20  	var ids []string
    21  	{
    22  		insert := [][]string{
    23  			[]string{"a", "b", "c", "d"},
    24  		}
    25  
    26  		for _, v := range insert {
    27  			ixn := &api.Intention{
    28  				SourceNS:        v[0],
    29  				SourceName:      v[1],
    30  				DestinationNS:   v[2],
    31  				DestinationName: v[3],
    32  				Action:          api.IntentionActionAllow,
    33  			}
    34  
    35  			id, _, err := client.Connect().IntentionCreate(ixn, nil)
    36  			require.NoError(err)
    37  			ids = append(ids, id)
    38  		}
    39  	}
    40  
    41  	finder := &Finder{Client: client}
    42  	ixn, err := finder.Find("a/b", "c/d")
    43  	require.NoError(err)
    44  	require.Equal(ids[0], ixn.ID)
    45  
    46  	ixn, err = finder.Find("a/c", "c/d")
    47  	require.NoError(err)
    48  	require.Nil(ixn)
    49  }