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

Function Persist

acceptance/testenv/testenv.go:65–86  ·  view source on GitHub ↗

Persist persists the environment stored in context in a ".persisted" file as JSON

(ctx context.Context)

Source from the content-addressed store, hash-verified

63
64// Persist persists the environment stored in context in a ".persisted" file as JSON
65func Persist(ctx context.Context) (bool, error) {
66 if !Persisted(ctx) {
67 return false, nil
68 }
69
70 values, ok := ctx.Value(persistedEnv).(*map[string]any)
71 if !ok {
72 return true, errors.New("did not find expected map type in Context for the persistedEnv value")
73 }
74
75 b, err := json.Marshal(values)
76 if err != nil {
77 return true, fmt.Errorf("unable to store JSON data in .persisted file: %v", err.Error())
78 }
79
80 err = persister(persistedFile, b, 0o644)
81 if err != nil {
82 return true, fmt.Errorf("unable to write to %s file: %v", persistedFile, err.Error())
83 }
84
85 return true, nil
86}
87
88// Persisted returns true if the test environment persists after the test has finished
89func Persisted(ctx context.Context) bool {

Callers 3

initializeScenarioFunction · 0.92
Test_PersistFunction · 0.85
Test_PersistOffFunction · 0.85

Calls 3

PersistedFunction · 0.85
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by 3

initializeScenarioFunction · 0.74
Test_PersistFunction · 0.68
Test_PersistOffFunction · 0.68