@@ -21,59 +21,101 @@ func Test_CreateTargetGroup_TGNotExist_Active(t *testing.T) {
2121 defer c .Finish ()
2222 ctx := context .TODO ()
2323
24- tgSpec := latticemodel.TargetGroupSpec {
25- Name : "test" ,
26- Config : latticemodel.TargetGroupConfig {
27- Port : int32 (8080 ),
28- Protocol : "HTTP" ,
29- VpcID : config .VpcID ,
30- EKSClusterName : "" ,
31- IsServiceImport : false ,
32- },
33- }
34- tgCreateInput := latticemodel.TargetGroup {
35- ResourceMeta : core.ResourceMeta {},
36- Spec : tgSpec ,
37- }
38- mockVpcLatticeSess := mocks .NewMockLattice (c )
39- arn := "12345678912345678912"
40- id := "12345678912345678912"
41- name := "test"
42- tgStatus := vpclattice .TargetGroupStatusActive
43- tgCreateOutput := & vpclattice.CreateTargetGroupOutput {
44- Arn : & arn ,
45- Id : & id ,
46- Name : & name ,
47- Status : & tgStatus ,
48- }
49- p := int64 (8080 )
50- prot := "HTTP"
51- emptystring := ""
52- config := & vpclattice.TargetGroupConfig {
53- Port : & p ,
54- Protocol : & prot ,
55- VpcIdentifier : & config .VpcID ,
56- ProtocolVersion : & emptystring ,
57- }
24+ tg_types := [2 ]string {"by-backendref" , "by-serviceexport" }
25+
26+ for _ , tg_type := range tg_types {
27+ var tgSpec latticemodel.TargetGroupSpec
28+
29+ if tg_type == "by-serviceexport" {
30+ // testing targetgroup for serviceexport
31+ tgSpec = latticemodel.TargetGroupSpec {
32+ Name : "test" ,
33+ Config : latticemodel.TargetGroupConfig {
34+ Port : int32 (8080 ),
35+ Protocol : "HTTP" ,
36+ VpcID : config .VpcID ,
37+ EKSClusterName : "" ,
38+ IsServiceImport : false ,
39+ IsServiceExport : true ,
40+ K8SServiceName : "exportsvc1" ,
41+ K8SServiceNamespace : "default" ,
42+ },
43+ }
44+ } else if tg_type == "by-backendref" {
45+ // testing targetgroup for serviceexport
46+ tgSpec = latticemodel.TargetGroupSpec {
47+ Name : "test" ,
48+ Config : latticemodel.TargetGroupConfig {
49+ Port : int32 (8080 ),
50+ Protocol : "HTTP" ,
51+ VpcID : config .VpcID ,
52+ EKSClusterName : "" ,
53+ IsServiceImport : false ,
54+ IsServiceExport : false ,
55+ K8SServiceName : "backend-svc1" ,
56+ K8SServiceNamespace : "default" ,
57+ K8SHTTPRouteName : "httproute1" ,
58+ K8SHTTPRouteNamespace : "default" ,
59+ },
60+ }
61+ }
62+ tgCreateInput := latticemodel.TargetGroup {
63+ ResourceMeta : core.ResourceMeta {},
64+ Spec : tgSpec ,
65+ }
66+ mockVpcLatticeSess := mocks .NewMockLattice (c )
67+ arn := "12345678912345678912"
68+ id := "12345678912345678912"
69+ name := "test"
70+ tgStatus := vpclattice .TargetGroupStatusActive
71+ tgCreateOutput := & vpclattice.CreateTargetGroupOutput {
72+ Arn : & arn ,
73+ Id : & id ,
74+ Name : & name ,
75+ Status : & tgStatus ,
76+ }
77+ p := int64 (8080 )
78+ prot := "HTTP"
79+ emptystring := ""
80+ config := & vpclattice.TargetGroupConfig {
81+ Port : & p ,
82+ Protocol : & prot ,
83+ VpcIdentifier : & config .VpcID ,
84+ ProtocolVersion : & emptystring ,
85+ }
5886
59- createTargetGroupInput := vpclattice.CreateTargetGroupInput {
60- Config : config ,
61- Name : & name ,
62- Type : & emptystring ,
63- }
87+ createTargetGroupInput := vpclattice.CreateTargetGroupInput {
88+ Config : config ,
89+ Name : & name ,
90+ Type : & emptystring ,
91+ Tags : make (map [string ]* string ),
92+ }
93+ createTargetGroupInput .Tags [latticemodel .K8SServiceNameKey ] = & tgSpec .Config .K8SServiceName
94+ createTargetGroupInput .Tags [latticemodel .K8SServiceNamespaceKey ] = & tgSpec .Config .K8SServiceNamespace
95+
96+ if tg_type == "by-serviceexport" {
97+ value := latticemodel .K8SServiceExportType
98+ createTargetGroupInput .Tags [latticemodel .K8SParentRefTypeKey ] = & value
99+ } else if tg_type == "by-backendref" {
100+ value := latticemodel .K8SHTTPRouteType
101+ createTargetGroupInput .Tags [latticemodel .K8SParentRefTypeKey ] = & value
102+ createTargetGroupInput .Tags [latticemodel .K8SHTTPRouteNameKey ] = & tgSpec .Config .K8SHTTPRouteName
103+ createTargetGroupInput .Tags [latticemodel .K8SHTTPRouteNamespaceKey ] = & tgSpec .Config .K8SHTTPRouteNamespace
104+ }
64105
65- listTgOutput := []* vpclattice.TargetGroupSummary {}
106+ listTgOutput := []* vpclattice.TargetGroupSummary {}
66107
67- mockCloud := mocks_aws .NewMockCloud (c )
68- mockVpcLatticeSess .EXPECT ().ListTargetGroupsAsList (ctx , gomock .Any ()).Return (listTgOutput , nil )
69- mockVpcLatticeSess .EXPECT ().CreateTargetGroupWithContext (ctx , & createTargetGroupInput ).Return (tgCreateOutput , nil )
70- mockCloud .EXPECT ().Lattice ().Return (mockVpcLatticeSess ).AnyTimes ()
71- tgManager := NewTargetGroupManager (mockCloud )
72- resp , err := tgManager .Create (ctx , & tgCreateInput )
108+ mockCloud := mocks_aws .NewMockCloud (c )
109+ mockVpcLatticeSess .EXPECT ().ListTargetGroupsAsList (ctx , gomock .Any ()).Return (listTgOutput , nil )
110+ mockVpcLatticeSess .EXPECT ().CreateTargetGroupWithContext (ctx , & createTargetGroupInput ).Return (tgCreateOutput , nil )
111+ mockCloud .EXPECT ().Lattice ().Return (mockVpcLatticeSess ).AnyTimes ()
112+ tgManager := NewTargetGroupManager (mockCloud )
113+ resp , err := tgManager .Create (ctx , & tgCreateInput )
73114
74- assert .Nil (t , err )
75- assert .Equal (t , resp .TargetGroupARN , arn )
76- assert .Equal (t , resp .TargetGroupID , id )
115+ assert .Nil (t , err )
116+ assert .Equal (t , resp .TargetGroupARN , arn )
117+ assert .Equal (t , resp .TargetGroupID , id )
118+ }
77119}
78120
79121// target group status is failed, and is active after creation
0 commit comments