Skip to content

Commit 4d25cfa

Browse files
authored
Unit tests for model package (#112)
Description of changes: Sdk.go coverage: 81.1% overall coverage: 56.21 % custom code coverage: > 85% By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 027d0aa commit 4d25cfa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2427
-24
lines changed

pkg/resource/model_package/hooks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ func (rm *resourceManager) requeueUntilCanModify(
6262
func (rm *resourceManager) customCheckRequiredFieldsMissingMethod(
6363
r *resource,
6464
) bool {
65-
return r.ko.Spec.ModelPackageName == nil && r.ko.Spec.ModelPackageGroupName == nil && r.ko.Status.ACKResourceMetadata.ARN == nil
65+
return r.ko.Spec.ModelPackageName == nil && r.ko.Spec.ModelPackageGroupName == nil && r.Identifiers().ARN() == nil
6666
}

pkg/resource/model_package/manager_test_suite_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2121
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
2222
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
23+
svcapitypes "github.com/aws-controllers-k8s/sagemaker-controller/apis/v1alpha1"
2324
"github.com/aws-controllers-k8s/sagemaker-controller/pkg/testutil"
2425
mocksvcsdkapi "github.com/aws-controllers-k8s/sagemaker-controller/test/mocks/aws-sdk-go/sagemaker"
2526
svcsdk "github.com/aws/aws-sdk-go/service/sagemaker"
@@ -103,15 +104,30 @@ func (d *testRunnerDelegate) Equal(a acktypes.AWSResource, b acktypes.AWSResourc
103104
ac := a.(*resource)
104105
bc := b.(*resource)
105106
// Ignore LastTransitionTime since it gets updated each run.
106-
opts := []cmp.Option{cmpopts.EquateEmpty(), cmpopts.IgnoreFields(ackv1alpha1.Condition{}, "LastTransitionTime")}
107+
opts := []cmp.Option{
108+
cmpopts.EquateEmpty(),
109+
cmpopts.IgnoreFields(ackv1alpha1.Condition{}, "LastTransitionTime"),
110+
cmpopts.IgnoreFields(svcapitypes.ModelPackageStatus{}, "CreationTime")}
107111

112+
var specMatch = false
113+
if cmp.Equal(ac.ko.Spec, bc.ko.Spec, opts...) {
114+
specMatch = true
115+
} else {
116+
fmt.Printf("Difference ko.Spec (-expected +actual):\n\n")
117+
fmt.Println(cmp.Diff(ac.ko.Spec, bc.ko.Spec, opts...))
118+
specMatch = false
119+
}
120+
121+
var statusMatch = false
108122
if cmp.Equal(ac.ko.Status, bc.ko.Status, opts...) {
109-
return true
123+
statusMatch = true
110124
} else {
111-
fmt.Printf("Difference (-expected +actual):\n\n")
125+
fmt.Printf("Difference ko.Status (-expected +actual):\n\n")
112126
fmt.Println(cmp.Diff(ac.ko.Status, bc.ko.Status, opts...))
113-
return false
127+
statusMatch = false
114128
}
129+
130+
return statusMatch && specMatch
115131
}
116132

117133
// 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+
"ModelPackageArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package/xgboost-unverisoned-model-package"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ModelPackageArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package/xgboost-model-package-group/1"
3+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"ApprovalDescription": null,
3+
"CertifyForMarketplace": false,
4+
"CreatedBy": null,
5+
"CreationTime": "2021-09-15T06:28:47.875Z",
6+
"InferenceSpecification": {
7+
"Containers": [
8+
{
9+
"ContainerHostname": null,
10+
"Image": "433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest",
11+
"ImageDigest": "sha256:a219d35e7bc4158e972b8e6fa18028b05bdc97a9fe8da2ba16f7e3dc1bc685b4",
12+
"ModelDataUrl": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz",
13+
"ProductId": null
14+
}
15+
],
16+
"SupportedContentTypes": [
17+
"text/csv"
18+
],
19+
"SupportedRealtimeInferenceInstanceTypes": [
20+
"ml.m5.large"
21+
],
22+
"SupportedResponseMIMETypes": [
23+
"text/csv"
24+
],
25+
"SupportedTransformInstanceTypes": [
26+
"ml.m5.large"
27+
]
28+
},
29+
"LastModifiedBy": null,
30+
"LastModifiedTime": null,
31+
"MetadataProperties": null,
32+
"ModelApprovalStatus": null,
33+
"ModelMetrics": null,
34+
"ModelPackageArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package/xgboost-unversioned-model-package-test",
35+
"ModelPackageDescription": "Description for model package",
36+
"ModelPackageGroupName": null,
37+
"ModelPackageName": "xgboost-unversioned-model-package-test",
38+
"ModelPackageStatus": "Deleting",
39+
"ModelPackageStatusDetails": {
40+
"ImageScanStatuses": [],
41+
"ValidationStatuses": [
42+
{
43+
"FailureReason": null,
44+
"Name": "Test-Model-Package",
45+
"Status": "Completed"
46+
}
47+
]
48+
},
49+
"ModelPackageVersion": null,
50+
"SourceAlgorithmSpecification": null,
51+
"ValidationSpecification": {
52+
"ValidationProfiles": [
53+
{
54+
"ProfileName": "Test-Model-Package",
55+
"TransformJobDefinition": {
56+
"BatchStrategy": null,
57+
"Environment": null,
58+
"MaxConcurrentTransforms": null,
59+
"MaxPayloadInMB": null,
60+
"TransformInput": {
61+
"CompressionType": null,
62+
"ContentType": "text/csv",
63+
"DataSource": {
64+
"S3DataSource": {
65+
"S3DataType": "S3Prefix",
66+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/batch/input-data"
67+
}
68+
},
69+
"SplitType": null
70+
},
71+
"TransformOutput": {
72+
"Accept": null,
73+
"AssembleWith": null,
74+
"KmsKeyId": "",
75+
"S3OutputPath": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/batch/output"
76+
},
77+
"TransformResources": {
78+
"InstanceCount": 1,
79+
"InstanceType": "ml.m5.large",
80+
"VolumeKmsKeyId": null
81+
}
82+
}
83+
}
84+
],
85+
"ValidationRole": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role-83w8wvq6kyyke4a7ns0e167ha5c5fndodr"
86+
}
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"ApprovalDescription": null,
3+
"CertifyForMarketplace": false,
4+
"CreatedBy": null,
5+
"CreationTime": "2021-09-15T06:28:47.875Z",
6+
"InferenceSpecification": {
7+
"Containers": [
8+
{
9+
"ContainerHostname": null,
10+
"Image": "433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest",
11+
"ImageDigest": "sha256:a219d35e7bc4158e972b8e6fa18028b05bdc97a9fe8da2ba16f7e3dc1bc685b4",
12+
"ModelDataUrl": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz",
13+
"ProductId": null
14+
}
15+
],
16+
"SupportedContentTypes": [
17+
"text/csv"
18+
],
19+
"SupportedRealtimeInferenceInstanceTypes": [
20+
"ml.m5.large"
21+
],
22+
"SupportedResponseMIMETypes": [
23+
"text/csv"
24+
],
25+
"SupportedTransformInstanceTypes": [
26+
"ml.m5.large"
27+
]
28+
},
29+
"LastModifiedBy": null,
30+
"LastModifiedTime": null,
31+
"MetadataProperties": null,
32+
"ModelApprovalStatus": null,
33+
"ModelMetrics": null,
34+
"ModelPackageArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package/xgboost-unversioned-model-package-test",
35+
"ModelPackageDescription": "Description for model package",
36+
"ModelPackageGroupName": null,
37+
"ModelPackageName": "xgboost-unversioned-model-package-test",
38+
"ModelPackageStatus": "Deleting",
39+
"ModelPackageStatusDetails": {
40+
"ImageScanStatuses": [],
41+
"ValidationStatuses": [
42+
{
43+
"FailureReason": null,
44+
"Name": "Test-Model-Package",
45+
"Status": "Completed"
46+
}
47+
]
48+
},
49+
"ModelPackageVersion": null,
50+
"SourceAlgorithmSpecification": null,
51+
"ValidationSpecification": {
52+
"ValidationProfiles": [
53+
{
54+
"ProfileName": "Test-Model-Package",
55+
"TransformJobDefinition": {
56+
"BatchStrategy": null,
57+
"Environment": null,
58+
"MaxConcurrentTransforms": null,
59+
"MaxPayloadInMB": null,
60+
"TransformInput": {
61+
"CompressionType": null,
62+
"ContentType": "text/csv",
63+
"DataSource": {
64+
"S3DataSource": {
65+
"S3DataType": "S3Prefix",
66+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/batch/input-data"
67+
}
68+
},
69+
"SplitType": null
70+
},
71+
"TransformOutput": {
72+
"Accept": null,
73+
"AssembleWith": null,
74+
"KmsKeyId": "",
75+
"S3OutputPath": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/batch/output"
76+
},
77+
"TransformResources": {
78+
"InstanceCount": 1,
79+
"InstanceType": "ml.m5.large",
80+
"VolumeKmsKeyId": null
81+
}
82+
}
83+
}
84+
],
85+
"ValidationRole": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role-83w8wvq6kyyke4a7ns0e167ha5c5fndodr"
86+
}
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"ApprovalDescription": null,
3+
"CertifyForMarketplace": false,
4+
"CreatedBy": null,
5+
"CreationTime": "2021-09-15T06:28:47.875Z",
6+
"InferenceSpecification": {
7+
"Containers": [
8+
{
9+
"ContainerHostname": null,
10+
"Image": "433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest",
11+
"ImageDigest": "sha256:a219d35e7bc4158e972b8e6fa18028b05bdc97a9fe8da2ba16f7e3dc1bc685b4",
12+
"ModelDataUrl": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/model/xgboost-mnist-model.tar.gz",
13+
"ProductId": null
14+
}
15+
],
16+
"SupportedContentTypes": [
17+
"text/csv"
18+
],
19+
"SupportedRealtimeInferenceInstanceTypes": [
20+
"ml.m5.large"
21+
],
22+
"SupportedResponseMIMETypes": [
23+
"text/csv"
24+
],
25+
"SupportedTransformInstanceTypes": [
26+
"ml.m5.large"
27+
]
28+
},
29+
"LastModifiedBy": null,
30+
"LastModifiedTime": null,
31+
"MetadataProperties": null,
32+
"ModelApprovalStatus": null,
33+
"ModelMetrics": null,
34+
"ModelPackageArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package/xgboost-unversioned-model-package-test",
35+
"ModelPackageDescription": "Description for model package",
36+
"ModelPackageGroupName": null,
37+
"ModelPackageName": "xgboost-unversioned-model-package-test",
38+
"ModelPackageStatus": "InProgress",
39+
"ModelPackageStatusDetails": {
40+
"ImageScanStatuses": [],
41+
"ValidationStatuses": [
42+
{
43+
"FailureReason": null,
44+
"Name": "Test-Model-Package",
45+
"Status": "InProgress"
46+
}
47+
]
48+
},
49+
"ModelPackageVersion": null,
50+
"SourceAlgorithmSpecification": null,
51+
"ValidationSpecification": {
52+
"ValidationProfiles": [
53+
{
54+
"ProfileName": "Test-Model-Package",
55+
"TransformJobDefinition": {
56+
"BatchStrategy": null,
57+
"Environment": null,
58+
"MaxConcurrentTransforms": null,
59+
"MaxPayloadInMB": null,
60+
"TransformInput": {
61+
"CompressionType": null,
62+
"ContentType": "text/csv",
63+
"DataSource": {
64+
"S3DataSource": {
65+
"S3DataType": "S3Prefix",
66+
"S3Uri": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/batch/input-data"
67+
}
68+
},
69+
"SplitType": null
70+
},
71+
"TransformOutput": {
72+
"Accept": null,
73+
"AssembleWith": null,
74+
"KmsKeyId": "",
75+
"S3OutputPath": "s3://source-data-bucket-592697580195-us-west-2/sagemaker/batch/output"
76+
},
77+
"TransformResources": {
78+
"InstanceCount": 1,
79+
"InstanceType": "ml.m5.large",
80+
"VolumeKmsKeyId": null
81+
}
82+
}
83+
}
84+
],
85+
"ValidationRole": "arn:aws:iam::123456789012:role/ack-sagemaker-execution-role-83w8wvq6kyyke4a7ns0e167ha5c5fndodr"
86+
}
87+
}

0 commit comments

Comments
 (0)