go.ligato.io/vpp-agent/v3@v3.5.0/cmd/agentctl/commands/config_test.go (about)

     1  //  Copyright (c) 2020 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package commands
    16  
    17  import (
    18  	"testing"
    19  
    20  	"google.golang.org/protobuf/proto"
    21  
    22  	"go.ligato.io/vpp-agent/v3/proto/ligato/configurator"
    23  	"go.ligato.io/vpp-agent/v3/proto/ligato/vpp"
    24  )
    25  
    26  func Test_prepareNotifyFilters(t *testing.T) {
    27  	type args struct {
    28  		filters []string
    29  	}
    30  	tests := []struct {
    31  		name string
    32  		args args
    33  		want []*configurator.Notification
    34  	}{
    35  		{
    36  			name: "vpp-notification",
    37  			args: args{
    38  				filters: []string{`{"vpp_notification":{}}`},
    39  			},
    40  			want: []*configurator.Notification{
    41  				{Notification: &configurator.Notification_VppNotification{VppNotification: &vpp.Notification{}}},
    42  			},
    43  		},
    44  	}
    45  	for _, tt := range tests {
    46  		t.Run(tt.name, func(t *testing.T) {
    47  			got, err := prepareNotifyFilters(tt.args.filters)
    48  			if err != nil {
    49  				t.Fatal(err)
    50  			}
    51  			if len(got) != len(tt.want) {
    52  				t.Fatalf("prepareNotifyFilters() = %v, want %v", got, tt.want)
    53  			}
    54  			for i, n := range got {
    55  				if !proto.Equal(n, tt.want[i]) {
    56  					t.Errorf("prepareNotifyFilters()[%d] = %v, want %v", i, n, tt.want[i])
    57  				}
    58  			}
    59  
    60  		})
    61  	}
    62  }