@@ -6,12 +6,15 @@ package utils
66import (
77 "context"
88 "crypto/rand"
9+ "errors"
910 "os"
11+ "strings"
1012
1113 "github.com/aws/aws-sdk-go-v2/aws"
1214 "github.com/aws/aws-sdk-go-v2/config"
1315 "github.com/aws/aws-sdk-go-v2/service/dynamodb"
1416 "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
17+ "github.com/aws/smithy-go"
1518)
1619
1720const (
@@ -130,6 +133,33 @@ func HandleError(err error) {
130133 }
131134}
132135
136+ func AssertServiceError (err error , service string , operation string , errorMessage string ) {
137+ if err == nil {
138+ panic ("Expected error but got no error" )
139+ }
140+ var oe * smithy.OperationError
141+ if errors .As (err , & oe ) {
142+ if oe .Service () != service {
143+ panic ("Expected service to be: " + service + " but got: " + oe .Service ())
144+ }
145+ if oe .Operation () != operation {
146+ panic ("Expected Operation to be: " + operation + " but got: " + oe .Operation ())
147+ }
148+ if ! strings .Contains (oe .Unwrap ().Error (), errorMessage ) {
149+ panic ("Expected message to contain: " + errorMessage + " but got: " + oe .Unwrap ().Error ())
150+ }
151+ }
152+ }
153+
154+ func AssertErrorMessage (err error , expectedMessage string ) {
155+ if err == nil {
156+ panic ("Expected error but got no error" )
157+ }
158+ if ! strings .Contains (err .Error (), expectedMessage ) {
159+ panic ("Expected error containing: `" + expectedMessage + "` but got:" + err .Error ())
160+ }
161+ }
162+
133163func GenerateAes256KeyBytes () []byte {
134164 key := make ([]byte , aesKeyBytes )
135165 // crypto/rand is used here for demonstration.
0 commit comments