Skip to content

Commit df7c2bc

Browse files
authored
Unit-tests for model-package-group (#106)
Description of changes: Sdk.go coverage: 96.1% Overall coverage: 64.3% Covers all custom code except this portion of [delete requeue](https://github.com/aws-controllers-k8s/sagemaker-controller/blob/f210ea74ef1bfa2c2e40f0a6d7b485fe6cb1249f/pkg/resource/model_package_group/sdk.go#L238). By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f210ea7 commit df7c2bc

29 files changed

+673
-17
lines changed

pkg/resource/model_package_group/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+
"ModelPackageGroupArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package-group/xgboost-model-package-group"
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"CreatedBy": null,
3+
"CreationTime": "2021-09-09T00:45:10.556Z",
4+
"ModelPackageGroupArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package-group/xgboost-model-package-group",
5+
"ModelPackageGroupDescription": "Description for model package group",
6+
"ModelPackageGroupName": "xgboost-model-package-group",
7+
"ModelPackageGroupStatus": "Deleting"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"CreatedBy": null,
3+
"CreationTime": "2021-09-09T00:45:10.556Z",
4+
"ModelPackageGroupArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package-group/xgboost-model-package-group",
5+
"ModelPackageGroupDescription": "Description for model package group",
6+
"ModelPackageGroupName": "xgboost-model-package-group",
7+
"ModelPackageGroupStatus": "InProgress"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"CreatedBy": null,
3+
"CreationTime": "2021-09-09T00:45:10.556Z",
4+
"ModelPackageGroupArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package-group/xgboost-model-package-group",
5+
"ModelPackageGroupDescription": "Description for model package group",
6+
"ModelPackageGroupName": "xgboost-model-package-group",
7+
"ModelPackageGroupStatus": "Pending"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"CreatedBy": null,
3+
"CreationTime": "2021-09-09T00:45:10.556Z",
4+
"ModelPackageGroupArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package-group/xgboost-model-package-group",
5+
"ModelPackageGroupDescription": "Description for model package group",
6+
"ModelPackageGroupName": "xgboost-model-package-group",
7+
"ModelPackageGroupStatus": "Completed"
8+
}
Lines changed: 174 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,177 @@
1-
tests:
1+
tests:
22
- name: "Model package group create tests"
33
description: "Part of model package group 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: "model_package_group/v1alpha1/mpg_invalid_before_create.yaml"
9-
svc_api:
10-
- operation: CreateModelPackageGroupWithContext
11-
error:
12-
code: InvalidParameterValue
13-
message: "The model package group name must not include a special character."
14-
invoke: Create
15-
expect:
16-
latest_state: "model_package_group/v1alpha1/mpg_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: CreateModelPackageGroupWithContext
11+
error:
12+
code: InvalidParameterValue
13+
message: "The model package group 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 model package group successfully (ARN in status)."
20+
given:
21+
desired_state: "v1alpha1/create/desired/success_before_create.yaml"
22+
svc_api:
23+
- operation: CreateModelPackageGroupWithContext
24+
output_fixture: "sdkapi/create/create_success.json"
25+
invoke: Create
26+
expect:
27+
latest_state: "v1alpha1/create/observed/success_after_create.yaml"
28+
error: nil
29+
- name: "Model package group readOne tests"
30+
description: "Testing the readOne operation"
31+
scenarios:
32+
- name: "ReadOne=MissingRequiredField"
33+
description: "Testing readOne when required field is missing. No API call is made and returns error."
34+
given:
35+
desired_state: "v1alpha1/readone/desired/missing_required_field.yaml"
36+
invoke: ReadOne
37+
expect:
38+
error: "resource not found"
39+
- name: "ReadOne=NotFound"
40+
description: "Testing readOne when Describe fails to find the resource on SageMaker"
41+
given:
42+
desired_state: "v1alpha1/readone/desired/after_create.yaml"
43+
svc_api:
44+
- operation: DescribeModelPackageGroupWithContext
45+
error:
46+
code: ValidationException
47+
message: "Model package group xgboost-model-package-group does not exist."
48+
invoke: ReadOne
49+
expect:
50+
error: "resource not found"
51+
- name: "ReadOne=Fail"
52+
description: "This test checks if the condition is updated if describe fails and readOne returns error"
53+
given:
54+
desired_state: "v1alpha1/readone/desired/after_create.yaml"
55+
svc_api:
56+
- operation: DescribeModelPackageGroupWithContext
57+
error:
58+
code: ServiceUnavailable
59+
message: "Server is down"
60+
invoke: ReadOne
61+
expect:
62+
latest_state: "v1alpha1/readone/observed/error_on_describe.yaml"
63+
error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
64+
- name: "ReadOne=Pending"
65+
description: "Testing readone right after create, the status should be in Pending with Resource synced being false."
66+
given:
67+
desired_state: "v1alpha1/readone/desired/pending_after_create.yaml"
68+
svc_api:
69+
- operation: DescribeModelPackageGroupWithContext
70+
output_fixture: "sdkapi/describe/describe_pending_after_create.json"
71+
invoke: ReadOne
72+
expect:
73+
latest_state: "v1alpha1/readone/observed/pending_after_create.yaml"
74+
- name: "ReadOne=Deleting"
75+
description: "Testing readone when deleting, resource synced should be false."
76+
given:
77+
desired_state: "v1alpha1/readone/desired/deleting.yaml"
78+
svc_api:
79+
- operation: DescribeModelPackageGroupWithContext
80+
output_fixture: "sdkapi/describe/describe_deleting.json"
81+
invoke: ReadOne
82+
expect:
83+
latest_state: "v1alpha1/readone/observed/deleting.yaml"
84+
- name: "ReadOne=InProgress"
85+
description: "Testing readone when inprogress, resource synced should be false."
86+
given:
87+
desired_state: "v1alpha1/readone/desired/inprogress_after_create.yaml"
88+
svc_api:
89+
- operation: DescribeModelPackageGroupWithContext
90+
output_fixture: "sdkapi/describe/describe_inprogress.json"
91+
invoke: ReadOne
92+
expect:
93+
latest_state: "v1alpha1/readone/observed/inprogess_after_create.yaml"
94+
- name: "ReadOne=AfterCreate"
95+
description: "Testing readOne after create, the status should have ARN."
96+
given:
97+
desired_state: "v1alpha1/readone/desired/after_create.yaml"
98+
svc_api:
99+
- operation: DescribeModelPackageGroupWithContext
100+
output_fixture: "sdkapi/describe/describe_success.json"
101+
invoke: ReadOne
102+
expect:
103+
latest_state: "v1alpha1/readone/observed/created.yaml"
104+
- name: "ReadOne=SuccessClearsConditions"
105+
description: "Testing a successful reconciliation clears conditions if terminal/recoverable condition were already set to true"
106+
given:
107+
desired_state: "v1alpha1/readone/desired/error_conditions_true.yaml"
108+
svc_api:
109+
- operation: DescribeModelPackageGroupWithContext
110+
output_fixture: "sdkapi/describe/describe_success.json"
111+
invoke: ReadOne
112+
expect:
113+
latest_state: "v1alpha1/readone/observed/conditions_clear_on_success.yaml"
114+
- name: "Model package group update tests"
115+
description: "Testing the Update operation"
116+
scenarios:
117+
- name: "Update=NotSupported"
118+
description: "This test checks if the controller throws error for update"
119+
given:
120+
desired_state: "v1alpha1/update/desired/updated_base.yaml"
121+
latest_state: "v1alpha1/readone/desired/after_create.yaml"
122+
invoke: Update
123+
expect:
124+
latest_state: "v1alpha1/update/observed/error_on_update.yaml"
125+
error: "not implemented"
126+
- name: "Model package group delete tests"
127+
description: "Testing the delete operation"
128+
scenarios:
129+
- name: "Delete=Fail"
130+
description: "This test checks if the condition is updated if delete fails and returns error"
131+
given:
132+
desired_state: "v1alpha1/readone/desired/after_create.yaml"
133+
svc_api:
134+
- operation: DeleteModelPackageGroupWithContext
135+
error:
136+
code: ServiceUnavailable
137+
message: "Server is down"
138+
invoke: Delete
139+
expect:
140+
latest_state: "v1alpha1/delete/observed/error_on_delete.yaml"
141+
error: "ServiceUnavailable: Server is down\n\tstatus code: 0, request id: "
142+
- name: "Delete=Successful"
143+
description: "This test checks if the Model package group is deleted successfully"
144+
given:
145+
desired_state: "v1alpha1/readone/desired/after_create.yaml"
146+
svc_api:
147+
- operation: DeleteModelPackageGroupWithContext
148+
- operation: DescribeModelPackageGroupWithContext
149+
error:
150+
code: ValidationException
151+
message: "Model package group xgboost-model-package-group does not exist."
152+
invoke: Delete
153+
expect:
154+
error: nil
155+
- name: "Delete=InProgress"
156+
description: "This test checks if the Model Package Group requeues while deleting. It should return a requeueWaitWhileStopping error."
157+
given:
158+
desired_state: "v1alpha1/delete/desired/delete_inprogress.yaml"
159+
svc_api:
160+
- operation: DeleteModelPackageGroupWithContext
161+
invoke: Delete
162+
expect:
163+
error: "ModelPackageGroup in InProgress state cannot be modified or deleted."
164+
- name: "Delete=Deleting"
165+
description: "This test checks if the Model Package Group requeues while deleting. It should return a requeueWaitWhileDeleting error."
166+
given:
167+
desired_state: "v1alpha1/delete/desired/delete_deleting.yaml"
168+
invoke: Delete
169+
expect:
170+
error: "ModelPackageGroup in Deleting state cannot be modified or deleted."
171+
- name: "Delete=Pending"
172+
description: "This test checks if the Model Package Group requeues while in pending state."
173+
given:
174+
desired_state: "v1alpha1/delete/desired/delete_pending.yaml"
175+
invoke: Delete
176+
expect:
177+
error: "ModelPackageGroup in Pending state cannot be modified or deleted."
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: sagemaker.services.k8s.aws/v1alpha1
2+
kind: ModelPackageGroup
3+
metadata:
4+
name: xgboost-model-package-group
5+
spec:
6+
modelPackageGroupName: xgboost-model-package-group
7+
modelPackageGroupDescription: "Description for model package group"
8+
tags:
9+
- key: algorithm
10+
value: xgboost
11+
- key: environment
12+
value: testing
13+
- key: customer
14+
value: test-user

0 commit comments

Comments
 (0)