@@ -6,12 +6,15 @@ package utils
6
6
import (
7
7
"context"
8
8
"crypto/rand"
9
+ "errors"
9
10
"os"
11
+ "strings"
10
12
11
13
"github.com/aws/aws-sdk-go-v2/aws"
12
14
"github.com/aws/aws-sdk-go-v2/config"
13
15
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
14
16
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
17
+ "github.com/aws/smithy-go"
15
18
)
16
19
17
20
const (
@@ -130,6 +133,33 @@ func HandleError(err error) {
130
133
}
131
134
}
132
135
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
+
133
163
func GenerateAes256KeyBytes () []byte {
134
164
key := make ([]byte , aesKeyBytes )
135
165
// crypto/rand is used here for demonstration.
0 commit comments