Skip to content

Commit 56e859b

Browse files
authored
endpoint config resource unit tests (#105)
Description of changes: - unit tests for endpoint config - sdk.go is at 90%, overall endpoint config pkg is at 68.5% Testing: `make test` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1512b68 commit 56e859b

16 files changed

+551
-17
lines changed

pkg/resource/endpoint_config/manager_test_suite_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,25 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
102102
// Ignore LastTransitionTime since it gets updated each run.
103103
opts := []cmp.Option{cmpopts.EquateEmpty(), cmpopts.IgnoreFields(ackv1alpha1.Condition{}, "LastTransitionTime")}
104104

105+
var specMatch = false
106+
if cmp.Equal(ac.ko.Spec, bc.ko.Spec, opts...) {
107+
specMatch = true
108+
} else {
109+
fmt.Printf("Difference ko.Spec (-expected +actual):\n\n")
110+
fmt.Println(cmp.Diff(ac.ko.Spec, bc.ko.Spec, opts...))
111+
specMatch = false
112+
}
113+
114+
var statusMatch = false
105115
if cmp.Equal(ac.ko.Status, bc.ko.Status, opts...) {
106-
return true
116+
statusMatch = true
107117
} else {
108-
fmt.Printf("Difference (-expected +actual):\n\n")
118+
fmt.Printf("Difference ko.Status (-expected +actual):\n\n")
109119
fmt.Println(cmp.Diff(ac.ko.Status, bc.ko.Status, opts...))
110-
return false
120+
statusMatch = false
111121
}
122+
123+
return statusMatch && specMatch
112124
}
113125

114126
// Checks to see if the given yaml file, with name stored as expectation,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"EndpointConfigArn": "arn:aws:sagemaker:us-west-2:123456789012:endpoint-config/single-variant-config"
3+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"CreationTime": "2021-09-09T01:05:28.204Z",
3+
"DataCaptureConfig": {
4+
"CaptureContentTypeHeader": {
5+
"CsvContentTypes": [
6+
"text/csv"
7+
],
8+
"JsonContentTypes": [
9+
"application/json"
10+
]
11+
},
12+
"CaptureOptions": [
13+
{
14+
"CaptureMode": "Input"
15+
},
16+
{
17+
"CaptureMode": "Output"
18+
}
19+
],
20+
"DestinationS3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/endpoint_config/datacapture",
21+
"EnableCapture": true,
22+
"InitialSamplingPercentage": 100,
23+
"KmsKeyId": null
24+
},
25+
"EndpointConfigArn": "arn:aws:sagemaker:us-west-2:123456789012:endpoint-config/single-variant-config",
26+
"EndpointConfigName": "single-variant-config",
27+
"KmsKeyId": null,
28+
"ProductionVariants": [
29+
{
30+
"AcceleratorType": null,
31+
"CoreDumpConfig": null,
32+
"InitialInstanceCount": 1,
33+
"InitialVariantWeight": 1,
34+
"InstanceType": "ml.c5.large",
35+
"ModelName": "single-variant-config-model",
36+
"VariantName": "AllTraffic"
37+
}
38+
]
39+
}
Lines changed: 116 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,119 @@
1-
tests:
1+
tests:
22
- name: "Endpoint config create tests"
33
description: "Part of endpoint config CRD tests."
44
scenarios:
5-
- name: "Create=InvalidInput"
6-
description: "Given one of the parameters is invalid, ko.Status shows a terminal condition"
7-
given:
8-
desired_state: "endpoint_config/v1alpha1/ec_invalid_before_create.yaml"
9-
svc_api:
10-
- operation: CreateEndpointConfigWithContext
11-
error:
12-
code: InvalidParameterValue
13-
message: "The endpoint config name must not include a special character."
14-
invoke: Create
15-
expect:
16-
latest_state: "endpoint_config/v1alpha1/ec_invalid_create_attempted.yaml"
17-
error: resource is in terminal condition
5+
- name: "Create=InvalidInput"
6+
description: "Given one of the parameters is invalid, Status shows a terminal condition"
7+
given:
8+
desired_state: "v1alpha1/create/desired/invalid_before_create.yaml"
9+
svc_api:
10+
- operation: CreateEndpointConfigWithContext
11+
error:
12+
code: InvalidParameterValue
13+
message: "The endpoint config name must not include a special character."
14+
invoke: Create
15+
expect:
16+
latest_state: "v1alpha1/create/observed/invalid_create_attempted.yaml"
17+
error: resource is in terminal condition
18+
- name: "Create=Valid"
19+
description: "Create a new endpoint config successfully (ARN in status)."
20+
given:
21+
desired_state: "v1alpha1/create/desired/success_before_create.yaml"
22+
svc_api:
23+
- operation: CreateEndpointConfigWithContext
24+
output_fixture: "sdkapi/create/success_create.json"
25+
invoke: Create
26+
expect:
27+
latest_state: "v1alpha1/create/observed/success_after_create.yaml"
28+
- name: "Endpoint config readOne tests"
29+
description: "Testing the readOne operation"
30+
scenarios:
31+
- name: "ReadOne=MissingRequiredField"
32+
description: "Testing readOne when required field is missing. No API call is made and returns error."
33+
given:
34+
desired_state: "v1alpha1/readone/desired/missing_required_field.yaml"
35+
invoke: ReadOne
36+
expect:
37+
error: "resource not found"
38+
- name: "ReadOne=NotFound"
39+
description: "Testing readOne when Describe fails to find the resource on SageMaker"
40+
given:
41+
desired_state: "v1alpha1/readone/desired/right_after_create.yaml"
42+
svc_api:
43+
- operation: DescribeEndpointConfigWithContext
44+
error:
45+
code: ValidationException
46+
message: "Could not find endpoint configuration single-variant-config"
47+
invoke: ReadOne
48+
expect:
49+
error: "resource not found"
50+
- name: "ReadOne=Fail"
51+
description: "This test checks if the condition is updated if describe fails and readOne returns error"
52+
given:
53+
desired_state: "v1alpha1/readone/desired/right_after_create.yaml"
54+
svc_api:
55+
- operation: DescribeEndpointConfigWithContext
56+
error:
57+
code: ServiceUnavailable
58+
message: "Server is down"
59+
invoke: ReadOne
60+
expect:
61+
latest_state: "v1alpha1/readone/observed/error_on_describe.yaml"
62+
error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
63+
- name: "ReadOne=AfterCreate"
64+
description: "Testing readOne right after create, there should be no delta."
65+
given:
66+
desired_state: "v1alpha1/readone/desired/right_after_create.yaml"
67+
svc_api:
68+
- operation: DescribeEndpointConfigWithContext
69+
output_fixture: "sdkapi/describe/success_describe.json"
70+
invoke: ReadOne
71+
expect:
72+
latest_state: "v1alpha1/readone/desired/right_after_create.yaml"
73+
- name: "ReadOne=SuccessClearsConditions"
74+
description: "Testing a successful reconiliation clears conditions if terminal/recoverable condition were already set to true"
75+
given:
76+
desired_state: "v1alpha1/readone/desired/error_conditions_true.yaml"
77+
svc_api:
78+
- operation: DescribeEndpointConfigWithContext
79+
output_fixture: "sdkapi/describe/success_describe.json"
80+
invoke: ReadOne
81+
expect:
82+
latest_state: "v1alpha1/readone/observed/conditions_clear_on_success.yaml"
83+
- name: "Endpoint config update tests"
84+
description: "Testing the update operation"
85+
scenarios:
86+
- name: "Update=NotSupported"
87+
description: "This test checks if the controller throws error for update"
88+
given:
89+
desired_state: "v1alpha1/update/desired/updated_base.yaml"
90+
latest_state: "v1alpha1/readone/desired/right_after_create.yaml"
91+
invoke: Update
92+
expect:
93+
latest_state: "v1alpha1/update/observed/error_on_update.yaml"
94+
error: "not implemented"
95+
- name: "Endpoint config delete tests"
96+
description: "Testing the delete operation"
97+
scenarios:
98+
- name: "Delete=Fail"
99+
description: "This test checks if the condition is updated if delete fails and returns error"
100+
given:
101+
desired_state: "v1alpha1/readone/desired/right_after_create.yaml"
102+
svc_api:
103+
- operation: DeleteEndpointConfigWithContext
104+
error:
105+
code: ServiceUnavailable
106+
message: "Server is down"
107+
invoke: Delete
108+
expect:
109+
latest_state: "v1alpha1/delete/observed/error_on_delete.yaml"
110+
error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
111+
- name: "Delete=Successful"
112+
description: "This test checks if the Endpoint config is deleted successfully"
113+
given:
114+
desired_state: "v1alpha1/readone/desired/right_after_create.yaml"
115+
svc_api:
116+
- operation: DeleteEndpointConfigWithContext
117+
invoke: Delete
118+
expect:
119+
error: nil
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: sagemaker.services.k8s.aws/v1alpha1
2+
kind: EndpointConfig
3+
metadata:
4+
name: single-variant-config
5+
spec:
6+
dataCaptureConfig:
7+
captureContentTypeHeader:
8+
csvContentTypes:
9+
- text/csv
10+
jsonContentTypes:
11+
- application/json
12+
captureOptions:
13+
- captureMode: Input
14+
- captureMode: Output
15+
destinationS3URI: s3://source-data-bucket-592697580195-us-west-2/sagemaker/endpoint_config/datacapture
16+
enableCapture: true
17+
initialSamplingPercentage: 100
18+
endpointConfigName: single-variant-config
19+
productionVariants:
20+
- initialInstanceCount: 1
21+
initialVariantWeight: 1
22+
instanceType: ml.c5.large
23+
modelName: single-variant-config-model
24+
variantName: AllTraffic
25+
tags:
26+
- key: confidentiality
27+
value: public
28+
- key: environment
29+
value: testing
30+
- key: customer
31+
value: test-user
32+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: sagemaker.services.k8s.aws/v1alpha1
2+
kind: EndpointConfig
3+
metadata:
4+
creationTimestamp: null
5+
name: single-variant-config
6+
spec:
7+
dataCaptureConfig:
8+
captureContentTypeHeader:
9+
csvContentTypes:
10+
- text/csv
11+
jsonContentTypes:
12+
- application/json
13+
captureOptions:
14+
- captureMode: Input
15+
- captureMode: Output
16+
destinationS3URI: s3://source-data-bucket-592697580195-us-west-2/sagemaker/endpoint_config/datacapture
17+
enableCapture: true
18+
initialSamplingPercentage: 100
19+
endpointConfigName: single-variant-config
20+
productionVariants:
21+
- initialInstanceCount: 1
22+
initialVariantWeight: 1
23+
instanceType: ml.c5.large
24+
modelName: single-variant-config-model
25+
variantName: AllTraffic
26+
tags:
27+
- key: confidentiality
28+
value: public
29+
- key: environment
30+
value: testing
31+
- key: customer
32+
value: test-user
33+
status:
34+
ackResourceMetadata:
35+
arn: arn:aws:sagemaker:us-west-2:123456789012:endpoint-config/single-variant-config
36+
ownerAccountID: ""
37+
conditions: []
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: sagemaker.services.k8s.aws/v1alpha1
2+
kind: EndpointConfig
3+
metadata:
4+
creationTimestamp: null
5+
name: single-variant-config
6+
spec:
7+
dataCaptureConfig:
8+
captureContentTypeHeader:
9+
csvContentTypes:
10+
- text/csv
11+
jsonContentTypes:
12+
- application/json
13+
captureOptions:
14+
- captureMode: Input
15+
- captureMode: Output
16+
destinationS3URI: s3://source-data-bucket-592697580195-us-west-2/sagemaker/endpoint_config/datacapture
17+
enableCapture: true
18+
initialSamplingPercentage: 100
19+
endpointConfigName: single-variant-config
20+
productionVariants:
21+
- initialInstanceCount: 1
22+
initialVariantWeight: 1
23+
instanceType: ml.c5.large
24+
modelName: single-variant-config-model
25+
variantName: AllTraffic
26+
tags:
27+
- key: confidentiality
28+
value: public
29+
- key: environment
30+
value: testing
31+
- key: customer
32+
value: test-user
33+
status:
34+
ackResourceMetadata:
35+
arn: arn:aws:sagemaker:us-west-2:123456789012:endpoint-config/single-variant-config
36+
ownerAccountID: ""
37+
conditions:
38+
- message: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
39+
status: "True"
40+
type: ACK.Recoverable
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: sagemaker.services.k8s.aws/v1alpha1
2+
kind: EndpointConfig
3+
metadata:
4+
creationTimestamp: null
5+
name: single-variant-config
6+
spec:
7+
dataCaptureConfig:
8+
captureContentTypeHeader:
9+
csvContentTypes:
10+
- text/csv
11+
jsonContentTypes:
12+
- application/json
13+
captureOptions:
14+
- captureMode: Input
15+
- captureMode: Output
16+
destinationS3URI: s3://source-data-bucket-592697580195-us-west-2/sagemaker/endpoint_config/datacapture
17+
enableCapture: true
18+
initialSamplingPercentage: 100
19+
endpointConfigName: single-variant-config
20+
productionVariants:
21+
- initialInstanceCount: 1
22+
initialVariantWeight: 1
23+
instanceType: ml.c5.large
24+
modelName: single-variant-config-model
25+
variantName: AllTraffic
26+
tags:
27+
- key: confidentiality
28+
value: public
29+
- key: environment
30+
value: testing
31+
- key: customer
32+
value: test-user
33+
status:
34+
ackResourceMetadata:
35+
ownerAccountID: ""
36+
conditions:
37+
- message: "InvalidParameterValue: The endpoint config name must not include a special
38+
character.\n\tstatus code: 0, request id: "
39+
status: "True"
40+
type: ACK.Terminal
41+
- message: "some dummy message"
42+
status: "True"
43+
type: ACK.Recoverable

0 commit comments

Comments
 (0)