MCPcopy Create free account
hub / github.com/conforma/cli / FetchState

Function FetchState

acceptance/testenv/testenv.go:184–201  ·  view source on GitHub ↗

FetchState fetches the state from the Context stored under S.Key()

(ctx context.Context)

Source from the content-addressed store, hash-verified

182
183// FetchState fetches the state from the Context stored under S.Key()
184func FetchState[S WithState](ctx context.Context) *S {
185 p := ctx.Value(persistedEnv)
186 if p == nil {
187 panic("need to invoke SetupState at least once")
188 }
189
190 newS := *new(S)
191 key := persistedKey(newS)
192
193 store := *p.(*map[string]any)
194
195 state := store[key]
196 if state == nil {
197 panic(fmt.Sprintf("no state found for key %s, make sure to invoke SetupState for %T first", key, newS))
198 }
199
200 return state.(*S)
201}
202
203// HasState returns true if the state for the provided type is present in the context
204func HasState[S WithState](ctx context.Context) bool {

Callers

nothing calls this directly

Calls 1

persistedKeyFunction · 0.85

Tested by

no test coverage detected