File: accountid_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 662,428 kB
  • sloc: java: 16,875; makefile: 432; sh: 175
file content (47 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package customizations

import (
	"context"
	"testing"

	"github.com/aws/smithy-go/middleware"
)

type accountIDBearer struct {
	AccountID *string
}

func TestDefaultAccountIDMiddleware(t *testing.T) {
	m := &DefaultAccountID{
		setDefaultAccountID: func(input interface{}, defaultAccountID string) interface{} {
			if bearer, ok := input.(accountIDBearer); ok && bearer.AccountID == nil {
				bearer.AccountID = &defaultAccountID
				return bearer
			}
			return input
		},
	}

	_, _, err := m.HandleInitialize(context.Background(),
		middleware.InitializeInput{
			Parameters: accountIDBearer{},
		},
		middleware.InitializeHandlerFunc(
			func(ctx context.Context, input middleware.InitializeInput) (
				out middleware.InitializeOutput, metadata middleware.Metadata, err error,
			) {
				params, ok := input.Parameters.(accountIDBearer)
				if !ok {
					t.Fatalf("expect struct input, got %T", input.Parameters)
				}
				if params.AccountID == nil || *params.AccountID != "-" {
					t.Errorf("expect `-` AccountID, got %v", params.AccountID)
				}
				return out, metadata, err
			}),
	)

	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
}