Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable saving config between steps in a single feature #103

Merged
merged 7 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/environment/magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (mr *MagicEnvironment) Prerequisite(ctx context.Context, t *testing.T, f *f
})
}

// Test implements Environment.Test.
// In the MagicEnvironment implementation, the Store that is inside of the
// Feature will be assigned to the context. If no Store is set on Feature,
// Test will create a new store.KVStore and set it on the feature and then
// apply it to the Context.
func (mr *MagicEnvironment) Test(ctx context.Context, t *testing.T, f *feature.Feature) {
t.Helper() // Helper marks the calling function as a test helper function.

Expand Down
5 changes: 5 additions & 0 deletions pkg/state/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ import (

type envKey struct{}

// ContextWith decorates the given context with the provided Store, and returns
// the resulting context.
func ContextWith(ctx context.Context, s Store) context.Context {
return context.WithValue(ctx, envKey{}, s)
}

// FromContext returns the Store from Context, if not found FromContext will
// panic.
// TODO: revisit if we really want to panic here... likely not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO panic is absolutely fine here, the Store must always exists in the context passed to StepFn. If it's not there, it's a reconciler-test bug

func FromContext(ctx context.Context) Store {
slinkydeveloper marked this conversation as resolved.
Show resolved Hide resolved
if e, ok := ctx.Value(envKey{}).(Store); ok {
return e
Expand Down