github.com/cilium/cilium@v1.16.2/pkg/hubble/filters/uuid_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Hubble
     3  
     4  package filters
     5  
     6  import (
     7  	"context"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  
    12  	flowpb "github.com/cilium/cilium/api/v1/flow"
    13  	v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
    14  )
    15  
    16  func TestUUIDFilter(t *testing.T) {
    17  	type args struct {
    18  		f  []*flowpb.FlowFilter
    19  		ev *v1.Event
    20  	}
    21  	tests := []struct {
    22  		name string
    23  		args args
    24  		want bool
    25  	}{
    26  		{
    27  			name: "nil",
    28  			args: args{
    29  				f: []*flowpb.FlowFilter{{
    30  					Uuid: []string{"43eea867-dd4b-4e5e-b2b8-fe80e0f51b06"},
    31  				}},
    32  				ev: nil,
    33  			},
    34  			want: false,
    35  		},
    36  		{
    37  			name: "match",
    38  			args: args{
    39  				f: []*flowpb.FlowFilter{{
    40  					Uuid: []string{
    41  						"43eea867-dd4b-4e5e-b2b8-fe80e0f51b06",
    42  						"4eb4d680-4793-43af-8446-79d72254084c",
    43  						"7ac83829-a655-4a9b-9729-70f8683858a5",
    44  						"a82c2c32-f410-47fb-9343-7788ea734c79", // this one
    45  						"e3549e80-6216-4179-93ed-b00d33b939ff",
    46  					},
    47  				}},
    48  				ev: &v1.Event{Event: &flowpb.Flow{
    49  					Uuid: "a82c2c32-f410-47fb-9343-7788ea734c79",
    50  				}},
    51  			},
    52  			want: true,
    53  		},
    54  		{
    55  			name: "no-match",
    56  			args: args{
    57  				f: []*flowpb.FlowFilter{{
    58  					Uuid: []string{
    59  						"43eea867-dd4b-4e5e-b2b8-fe80e0f51b06",
    60  						"4eb4d680-4793-43af-8446-79d72254084c",
    61  						"7ac83829-a655-4a9b-9729-70f8683858a5",
    62  						"e3549e80-6216-4179-93ed-b00d33b939ff",
    63  					},
    64  				}},
    65  				ev: &v1.Event{Event: &flowpb.Flow{
    66  					Uuid: "a82c2c32-f410-47fb-9343-7788ea734c79",
    67  				}},
    68  			},
    69  			want: false,
    70  		},
    71  	}
    72  
    73  	for _, tt := range tests {
    74  		t.Run(tt.name, func(t *testing.T) {
    75  			fl, err := BuildFilterList(context.Background(), tt.args.f, []OnBuildFilter{&UUIDFilter{}})
    76  			assert.NoError(t, err)
    77  			assert.Equal(t, tt.want, fl.MatchOne(tt.args.ev))
    78  		})
    79  	}
    80  }