@@ -19,6 +19,7 @@ import (
1919 "github.com/stretchr/testify/assert"
2020 "github.com/stretchr/testify/require"
2121
22+ "github.com/aws-controllers-k8s/code-generator/pkg/generate/code"
2223 "github.com/aws-controllers-k8s/code-generator/pkg/testutil"
2324)
2425
@@ -66,3 +67,76 @@ func TestSageMaker_ARN_Field_Override(t *testing.T) {
6667 assert .Equal (true , crd .IsPrimaryARNField ("JobDefinitionArn" ))
6768
6869}
70+
71+ func TestSageMaker_Error_Prefix_Message (t * testing.T ) {
72+ assert := assert .New (t )
73+ require := require .New (t )
74+
75+ g := testutil .NewGeneratorForService (t , "sagemaker" )
76+
77+ crds , err := g .GetCRDs ()
78+ require .Nil (err )
79+
80+ crd := getCRDByName ("TrainingJob" , crds )
81+ require .NotNil (crd )
82+
83+ require .NotNil (crd .Ops )
84+
85+ assert .NotNil (crd .Ops .ReadOne )
86+
87+ // "DescribeTrainingJob":{
88+ // "name":"DescribeTrainingJob",
89+ // "http":{
90+ // "method":"POST",
91+ // "requestUri":"/"
92+ // },
93+ // "input":{"shape":"DescribeTrainingJobRequest"},
94+ // "output":{"shape":"DescribeTrainingJobResponse"},
95+ // "errors":[
96+ // {"shape":"ResourceNotFound"}
97+ // ]
98+ // },
99+
100+ // Which does not indicate that the error is a 404 :( So, the logic in the
101+ // CRD.ExceptionCode(404) method needs to get its override from the
102+ // generate.yaml configuration file.
103+ assert .Equal ("ValidationException" , crd .ExceptionCode (404 ))
104+
105+ // Validation Exception has prefix Requested resource not found.
106+ assert .Equal ("&& strings.HasPrefix(awsErr.Message(), \" Requested resource not found\" ) " , code .CheckExceptionMessage (crd .Config (), crd , 404 ))
107+ }
108+
109+ func TestSageMaker_Error_Suffix_Message (t * testing.T ) {
110+ assert := assert .New (t )
111+ require := require .New (t )
112+
113+ g := testutil .NewGeneratorForService (t , "sagemaker" )
114+
115+ crds , err := g .GetCRDs ()
116+ require .Nil (err )
117+
118+ crd := getCRDByName ("ModelPackageGroup" , crds )
119+ require .NotNil (crd )
120+
121+ require .NotNil (crd .Ops )
122+ assert .NotNil (crd .Ops .ReadOne )
123+
124+ // "DescribeModelPackageGroup":{
125+ // "name":"DescribeModelPackageGroup",
126+ // "http":{
127+ // "method":"POST",
128+ // "requestUri":"/"
129+ // },
130+ // "input":{"shape":"DescribeModelPackageGroupInput"},
131+ // "output":{"shape":"DescribeModelPackageGroupOutput"}
132+ // }
133+
134+ // Does not list an error however a ValidationException can occur
135+ // Which does not indicate that the error is a 404 :( So, the logic in the
136+ // CRD.ExceptionCode(404) method needs to get its override from the
137+ // generate.yaml configuration file.
138+ assert .Equal ("ValidationException" , crd .ExceptionCode (404 ))
139+
140+ // Validation Exception has suffix ModelPackageGroup arn:aws:sagemaker:/ does not exist
141+ assert .Equal ("&& strings.HasSuffix(awsErr.Message(), \" does not exist.\" ) " , code .CheckExceptionMessage (crd .Config (), crd , 404 ))
142+ }
0 commit comments