github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/lb_unit_test.go (about) 1 //go:build unit || lb || lbAppProfile || ALL 2 3 /* 4 * Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. 5 */ 6 7 package govcd 8 9 import "testing" 10 11 func Test_extractNSXObjectIDFromPath(t *testing.T) { 12 type args struct { 13 header string 14 } 15 tests := []struct { 16 name string 17 args args 18 want string 19 wantErr bool 20 }{ 21 { 22 name: "Empty", 23 args: args{header: ""}, 24 want: "", 25 wantErr: true, 26 }, 27 { 28 name: "No URL in Path", 29 args: args{header: "invalid_location_header"}, 30 want: "", 31 wantErr: true, 32 }, 33 { 34 name: "No Slash", 35 args: args{header: "applicationProfile-4"}, 36 want: "", 37 wantErr: true, 38 }, 39 { 40 name: "Trailing Slash", 41 args: args{header: "/network/edges/edge-3/loadbalancer/config/applicationprofiles/applicationProfile-4/"}, 42 want: "applicationProfile-4", 43 wantErr: false, 44 }, 45 { 46 name: "No Trailing Slash", 47 args: args{header: "/network/edges/edge-3/loadbalancer/config/applicationprofiles/applicationProfile-4"}, 48 want: "applicationProfile-4", 49 wantErr: false, 50 }, 51 } 52 for _, tt := range tests { 53 t.Run(tt.name, func(t *testing.T) { 54 got, err := extractNsxObjectIdFromPath(tt.args.header) 55 if (err != nil) != tt.wantErr { 56 t.Errorf("extractNsxObjectIdFromPath() error = %v, wantErr %v", err, tt.wantErr) 57 return 58 } 59 if got != tt.want { 60 t.Errorf("extractNsxObjectIdFromPath() = %v, want %v", got, tt.want) 61 } 62 }) 63 } 64 }