MCPcopy Create free account
hub / github.com/aws/smithy-go / TestStackValues

Function TestStackValues

middleware/stack_values_test.go:8–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestStackValues(t *testing.T) {
9 ctx := context.Background()
10
11 // Ensure empty stack values don't return something
12 if v := GetStackValue(ctx, "some key"); v != nil {
13 t.Fatalf("expect not-existing key to be nil, got %T, %v", v, v)
14 }
15
16 // Add a stack values, ensure not polluting previous context.
17 ctx2 := WithStackValue(ctx, "some key", "foo")
18 ctx2 = WithStackValue(ctx2, "some other key", "bar")
19 if v := GetStackValue(ctx, "some key"); v != nil {
20 t.Fatalf("expect not-existing key to be nil, got %T, %v", v, v)
21 }
22 if v, ok := GetStackValue(ctx2, "some key").(string); !ok || v != "foo" {
23 t.Fatalf("expect key to be present")
24 }
25 if v, ok := GetStackValue(ctx2, "some other key").(string); !ok || v != "bar" {
26 t.Fatalf("expect key to be present")
27 }
28
29 // Clear the stack values ensure new context doesn't have any stack values.
30 ctx3 := ClearStackValues(ctx2)
31 if v, ok := GetStackValue(ctx2, "some key").(string); !ok || v != "foo" {
32 t.Fatalf("expect key to be present")
33 }
34 if v := GetStackValue(ctx3, "some key"); v != nil {
35 t.Fatalf("expect not-existing key to be nil, got %T, %v", v, v)
36 }
37 if v := GetStackValue(ctx3, "some other key"); v != nil {
38 t.Fatalf("expect not-existing key to be nil, got %T, %v", v, v)
39 }
40}

Callers

nothing calls this directly

Calls 3

GetStackValueFunction · 0.85
WithStackValueFunction · 0.85
ClearStackValuesFunction · 0.85

Tested by

no test coverage detected