@@ -23,6 +23,7 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
2323 cases := map [string ]struct {
2424 response * smithyhttp.Response
2525 validateOptions func (* validateOutputPayloadChecksum )
26+ modifyContext func (context.Context ) context.Context
2627 expectHaveAlgorithmsUsed bool
2728 expectAlgorithmsUsed []string
2829 expectErr string
@@ -31,6 +32,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
3132 expectPayload []byte
3233 }{
3334 "success" : {
35+ modifyContext : func (ctx context.Context ) context.Context {
36+ return setContextOutputValidationMode (ctx , "ENABLED" )
37+ },
3438 response : & smithyhttp.Response {
3539 Response : & http.Response {
3640 StatusCode : 200 ,
@@ -47,6 +51,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
4751 expectPayload : []byte ("hello world" ),
4852 },
4953 "failure" : {
54+ modifyContext : func (ctx context.Context ) context.Context {
55+ return setContextOutputValidationMode (ctx , "ENABLED" )
56+ },
5057 response : & smithyhttp.Response {
5158 Response : & http.Response {
5259 StatusCode : 200 ,
@@ -61,6 +68,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
6168 expectReadErr : "checksum did not match" ,
6269 },
6370 "read error" : {
71+ modifyContext : func (ctx context.Context ) context.Context {
72+ return setContextOutputValidationMode (ctx , "ENABLED" )
73+ },
6474 response : & smithyhttp.Response {
6575 Response : & http.Response {
6676 StatusCode : 200 ,
@@ -75,6 +85,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
7585 expectReadErr : "some read error" ,
7686 },
7787 "unsupported algorithm" : {
88+ modifyContext : func (ctx context.Context ) context.Context {
89+ return setContextOutputValidationMode (ctx , "ENABLED" )
90+ },
7891 response : & smithyhttp.Response {
7992 Response : & http.Response {
8093 StatusCode : 200 ,
@@ -89,7 +102,39 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
89102 expectLogged : "no supported checksum" ,
90103 expectPayload : []byte ("hello world" ),
91104 },
105+ "no output validation model" : {
106+ response : & smithyhttp.Response {
107+ Response : & http.Response {
108+ StatusCode : 200 ,
109+ Header : func () http.Header {
110+ h := http.Header {}
111+ return h
112+ }(),
113+ Body : ioutil .NopCloser (strings .NewReader ("hello world" )),
114+ },
115+ },
116+ expectPayload : []byte ("hello world" ),
117+ },
118+ "unknown output validation model" : {
119+ modifyContext : func (ctx context.Context ) context.Context {
120+ return setContextOutputValidationMode (ctx , "something else" )
121+ },
122+ response : & smithyhttp.Response {
123+ Response : & http.Response {
124+ StatusCode : 200 ,
125+ Header : func () http.Header {
126+ h := http.Header {}
127+ return h
128+ }(),
129+ Body : ioutil .NopCloser (strings .NewReader ("hello world" )),
130+ },
131+ },
132+ expectPayload : []byte ("hello world" ),
133+ },
92134 "success ignore multipart checksum" : {
135+ modifyContext : func (ctx context.Context ) context.Context {
136+ return setContextOutputValidationMode (ctx , "ENABLED" )
137+ },
93138 response : & smithyhttp.Response {
94139 Response : & http.Response {
95140 StatusCode : 200 ,
@@ -109,6 +154,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
109154 expectPayload : []byte ("hello world" ),
110155 },
111156 "success skip ignore multipart checksum" : {
157+ modifyContext : func (ctx context.Context ) context.Context {
158+ return setContextOutputValidationMode (ctx , "ENABLED" )
159+ },
112160 response : & smithyhttp.Response {
113161 Response : & http.Response {
114162 StatusCode : 200 ,
@@ -136,6 +184,10 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
136184 fmt .Fprintf (& logged , format , v ... )
137185 }))
138186
187+ if c .modifyContext != nil {
188+ ctx = c .modifyContext (ctx )
189+ }
190+
139191 validateOutput := validateOutputPayloadChecksum {
140192 Algorithms : []Algorithm {
141193 AlgorithmSHA1 , AlgorithmCRC32 , AlgorithmCRC32C ,
@@ -187,10 +239,8 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
187239 return
188240 }
189241
190- if c .expectLogged != "" {
191- if e , a := c .expectLogged , logged .String (); ! strings .Contains (a , e ) {
192- t .Errorf ("expected %q logged in:\n %s" , e , a )
193- }
242+ if e , a := c .expectLogged , logged .String (); ! strings .Contains (a , e ) || ! ((e == "" ) == (a == "" )) {
243+ t .Errorf ("expected %q logged in:\n %s" , e , a )
194244 }
195245
196246 if diff := cmp .Diff (string (c .expectPayload ), string (actualPayload )); diff != "" {
0 commit comments