Skip to content

Commit 47e17a1

Browse files
committed
Add K8S_CONTROLLER attributes unit tests
1 parent 80c64e8 commit 47e17a1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pkg/cloudmap/client_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func TestServiceDiscoveryClient_RegisterEndpoints(t *testing.T) {
310310
model.EndpointHostnameAttr: test.Hostname,
311311
model.EndpointNodeNameAttr: test.Nodename,
312312
model.ServiceExportCreationAttr: strconv.FormatInt(test.SvcExportCreationTimestamp, 10),
313+
model.K8sVersionAttr: test.PackageVersion,
313314
}
314315
attrs2 := map[string]string{
315316
model.ClusterIdAttr: test.ClusterId1,
@@ -327,6 +328,7 @@ func TestServiceDiscoveryClient_RegisterEndpoints(t *testing.T) {
327328
model.EndpointHostnameAttr: test.Hostname,
328329
model.EndpointNodeNameAttr: test.Nodename,
329330
model.ServiceExportCreationAttr: strconv.FormatInt(test.SvcExportCreationTimestamp, 10),
331+
model.K8sVersionAttr: test.PackageVersion,
330332
}
331333

332334
tc.mockApi.EXPECT().RegisterInstance(context.TODO(), test.SvcId, test.EndptId1, attrs1).
@@ -370,6 +372,7 @@ func TestServiceDiscoveryClient_DeleteEndpoints(t *testing.T) {
370372
}
371373

372374
func getTestSdClient(t *testing.T) *testSdClient {
375+
test.SetTestVersion()
373376
mockController := gomock.NewController(t)
374377
mockCache := cloudmapMock.NewMockServiceDiscoveryClientCache(mockController)
375378
mockApi := cloudmapMock.NewMockServiceDiscoveryApi(mockController)
@@ -409,6 +412,7 @@ func getHttpInstanceSummaryForTest() []types.HttpInstanceSummary {
409412
model.EndpointHostnameAttr: test.Hostname,
410413
model.EndpointNodeNameAttr: test.Nodename,
411414
model.ServiceExportCreationAttr: strconv.FormatInt(test.SvcExportCreationTimestamp, 10),
415+
model.K8sVersionAttr: test.PackageVersion,
412416
},
413417
},
414418
{
@@ -429,6 +433,7 @@ func getHttpInstanceSummaryForTest() []types.HttpInstanceSummary {
429433
model.EndpointHostnameAttr: test.Hostname,
430434
model.EndpointNodeNameAttr: test.Nodename,
431435
model.ServiceExportCreationAttr: strconv.FormatInt(test.SvcExportCreationTimestamp, 10),
436+
model.K8sVersionAttr: test.PackageVersion,
432437
},
433438
},
434439
}

pkg/controllers/multicluster/serviceexport_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func getServiceExportScheme() *runtime.Scheme {
205205
}
206206

207207
func getServiceExportReconciler(t *testing.T, mockClient *cloudmapMock.MockServiceDiscoveryClient, client client.Client) *ServiceExportReconciler {
208+
test.SetTestVersion()
208209
return &ServiceExportReconciler{
209210
Client: client,
210211
Log: common.NewLoggerWithLogr(testr.New(t)),

test/test-constants.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package test
22

33
import (
44
"fmt"
5-
5+
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/version"
66
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
77

88
aboutv1alpha1 "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/apis/about/v1alpha1"
@@ -46,8 +46,14 @@ const (
4646
SvcExportCreationTimestamp int64 = 1640995200000
4747
Hostname = "host"
4848
Nodename = "node"
49+
PackageVersion = "aws-cloud-map-mcs-controller-for-k8s 0.0.1 (abcd)"
4950
)
5051

52+
func SetTestVersion() {
53+
version.GitVersion = "v0.0.1"
54+
version.GitCommit = "abcd"
55+
}
56+
5157
func GetTestHttpNamespace() *model.Namespace {
5258
return &model.Namespace{
5359
Id: HttpNsId,
@@ -111,7 +117,7 @@ func GetTestEndpoint1() *model.Endpoint {
111117
ClusterSetId: ClusterSet,
112118
ServiceType: model.ClusterSetIPType,
113119
ServiceExportCreationTimestamp: SvcExportCreationTimestamp,
114-
Attributes: make(map[string]string),
120+
Attributes: map[string]string{model.K8sVersionAttr: PackageVersion},
115121
}
116122
}
117123

@@ -137,7 +143,7 @@ func GetTestEndpoint2() *model.Endpoint {
137143
ClusterSetId: ClusterSet,
138144
ServiceType: model.ClusterSetIPType,
139145
ServiceExportCreationTimestamp: SvcExportCreationTimestamp,
140-
Attributes: make(map[string]string),
146+
Attributes: map[string]string{model.K8sVersionAttr: PackageVersion},
141147
}
142148
}
143149

0 commit comments

Comments
 (0)