(t *testing.T)
| 98 | } |
| 99 | |
| 100 | func Test_SetupStateExistingValue(t *testing.T) { |
| 101 | existing := another{Val: 2.5} |
| 102 | |
| 103 | ctx := context.WithValue(context.TODO(), persistedEnv, &map[string]any{ |
| 104 | "testenv.key.1": &existing, |
| 105 | }) |
| 106 | |
| 107 | var s *stateful |
| 108 | ctx, err := SetupState(ctx, &s) |
| 109 | |
| 110 | assert.NoError(t, err) |
| 111 | |
| 112 | var a *another |
| 113 | ctx, err = SetupState(ctx, &a) |
| 114 | |
| 115 | assert.NoError(t, err) |
| 116 | |
| 117 | expectedStateful := stateful{Number: 0, Str: ""} |
| 118 | assert.Equal(t, expectedStateful, *s) |
| 119 | assert.Equal(t, &expectedStateful, FetchState[stateful](ctx)) |
| 120 | |
| 121 | expectedAnother := another{Val: 2.5} |
| 122 | assert.Equal(t, expectedAnother, *a) |
| 123 | assert.Equal(t, &expectedAnother, FetchState[another](ctx)) |
| 124 | } |
| 125 | |
| 126 | func Test_SetupStateMutateExistingValue(t *testing.T) { |
| 127 | var s1 *stateful |
nothing calls this directly
no test coverage detected