|
| 1 | +package vpc |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" |
| 10 | + v1 "k8s.io/api/core/v1" |
| 11 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 12 | + |
| 13 | + "github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha1" |
| 14 | + "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common" |
| 15 | +) |
| 16 | + |
| 17 | +func Test_buildNSXLBS(t *testing.T) { |
| 18 | + type args struct { |
| 19 | + obj *v1alpha1.NetworkInfo |
| 20 | + nsObj *v1.Namespace |
| 21 | + cluster string |
| 22 | + lbsSize string |
| 23 | + vpcPath string |
| 24 | + relaxScaleValidation *bool |
| 25 | + } |
| 26 | + tests := []struct { |
| 27 | + name string |
| 28 | + args args |
| 29 | + want *model.LBService |
| 30 | + wantErr assert.ErrorAssertionFunc |
| 31 | + }{ |
| 32 | + { |
| 33 | + name: "1", |
| 34 | + args: args{ |
| 35 | + obj: &v1alpha1.NetworkInfo{ |
| 36 | + ObjectMeta: metav1.ObjectMeta{Namespace: "ns1"}, |
| 37 | + VPCs: nil, |
| 38 | + }, |
| 39 | + nsObj: &v1.Namespace{ |
| 40 | + ObjectMeta: metav1.ObjectMeta{Name: "ns1", UID: "nsuid1"}, |
| 41 | + }, |
| 42 | + cluster: "cluster1", |
| 43 | + lbsSize: model.LBService_SIZE_SMALL, |
| 44 | + vpcPath: "/vpc1", |
| 45 | + relaxScaleValidation: nil, |
| 46 | + }, |
| 47 | + want: &model.LBService{ |
| 48 | + Id: common.String("nsuid1"), |
| 49 | + DisplayName: common.String("vpc-cluster1--ns1"), |
| 50 | + Tags: []model.Tag{ |
| 51 | + { |
| 52 | + Scope: common.String(common.TagScopeCluster), |
| 53 | + Tag: common.String("cluster1"), |
| 54 | + }, |
| 55 | + { |
| 56 | + Scope: common.String(common.TagScopeVersion), |
| 57 | + Tag: common.String(strings.Join(common.TagValueVersion, ".")), |
| 58 | + }, |
| 59 | + {Scope: common.String(common.TagScopeNamespace), Tag: common.String("ns1")}, |
| 60 | + {Scope: common.String(common.TagScopeNamespaceUID), Tag: common.String("nsuid1")}, |
| 61 | + {Scope: common.String(common.TagScopeCreatedFor), Tag: common.String(common.TagValueSLB)}, |
| 62 | + }, |
| 63 | + Size: common.String(model.LBService_SIZE_SMALL), |
| 64 | + ConnectivityPath: common.String("/vpc1"), |
| 65 | + RelaxScaleValidation: nil, |
| 66 | + }, |
| 67 | + wantErr: assert.NoError, |
| 68 | + }, |
| 69 | + } |
| 70 | + for _, tt := range tests { |
| 71 | + t.Run(tt.name, func(t *testing.T) { |
| 72 | + got, err := buildNSXLBS(tt.args.obj, tt.args.nsObj, tt.args.cluster, tt.args.lbsSize, tt.args.vpcPath, tt.args.relaxScaleValidation) |
| 73 | + if !tt.wantErr(t, err, fmt.Sprintf("buildNSXLBS(%v, %v, %v, %v, %v, %v)", tt.args.obj, tt.args.nsObj, tt.args.cluster, tt.args.lbsSize, tt.args.vpcPath, tt.args.relaxScaleValidation)) { |
| 74 | + return |
| 75 | + } |
| 76 | + assert.Equalf(t, tt.want, got, "buildNSXLBS(%v, %v, %v, %v, %v, %v)", tt.args.obj, tt.args.nsObj, tt.args.cluster, tt.args.lbsSize, tt.args.vpcPath, tt.args.relaxScaleValidation) |
| 77 | + }) |
| 78 | + } |
| 79 | +} |
0 commit comments