github.com/cilium/cilium@v1.16.2/pkg/alibabacloud/utils/utils_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package utils
     5  
     6  import (
     7  	"reflect"
     8  	"testing"
     9  )
    10  
    11  func TestGetENIIndexFromTags(t *testing.T) {
    12  	type args struct {
    13  		tags map[string]string
    14  	}
    15  	tests := []struct {
    16  		name string
    17  		args args
    18  		want int
    19  	}{
    20  		{
    21  			name: "default 0",
    22  			args: args{tags: map[string]string{}},
    23  			want: 0,
    24  		},
    25  		{
    26  			name: "index 1",
    27  			args: args{tags: map[string]string{eniIndexTagKey: "1"}},
    28  			want: 1,
    29  		},
    30  	}
    31  	for _, tt := range tests {
    32  		t.Run(tt.name, func(t *testing.T) {
    33  			if got := GetENIIndexFromTags(tt.args.tags); got != tt.want {
    34  				t.Errorf("GetENIIndexFromTags() = %v, want %v", got, tt.want)
    35  			}
    36  		})
    37  	}
    38  }
    39  
    40  func TestFillTagWithENIIndex(t *testing.T) {
    41  	type args struct {
    42  		tags  map[string]string
    43  		index int
    44  	}
    45  	tests := []struct {
    46  		name string
    47  		args args
    48  		want map[string]string
    49  	}{
    50  		{
    51  			name: "index 1",
    52  			args: args{
    53  				tags:  map[string]string{"key": "val"},
    54  				index: 1,
    55  			},
    56  			want: map[string]string{"key": "val", eniIndexTagKey: "1"},
    57  		},
    58  	}
    59  	for _, tt := range tests {
    60  		t.Run(tt.name, func(t *testing.T) {
    61  			if got := FillTagWithENIIndex(tt.args.tags, tt.args.index); !reflect.DeepEqual(got, tt.want) {
    62  				t.Errorf("FillTagWithENIIndex() = %v, want %v", got, tt.want)
    63  			}
    64  		})
    65  	}
    66  }