From 165baa4ee12478e7345f95c362f6bc2cc12634fc Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 11 Jul 2018 13:19:14 -0400 Subject: [PATCH] e2e/framework: add framework.F context --- e2e/framework/context.go | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 e2e/framework/context.go diff --git a/e2e/framework/context.go b/e2e/framework/context.go new file mode 100644 index 000000000..f441a5516 --- /dev/null +++ b/e2e/framework/context.go @@ -0,0 +1,61 @@ +package framework + +import ( + "testing" + + "github.com/hashicorp/nomad/helper/uuid" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// F is the framework context that is passed to each test. +// It is used to access the *testing.T context as well as testify helpers +type F struct { + id string + *require.Assertions + assert *assert.Assertions + t *testing.T + + data map[interface{}]interface{} +} + +func newF(t *testing.T) *F { + return newFWithID(uuid.Generate()[:8], t) +} + +func newFWithID(id string, t *testing.T) *F { + ft := &F{ + id: id, + t: t, + Assertions: require.New(t), + assert: assert.New(t), + } + + return ft +} + +// Assert fetches an assert flavor of testify assertions +// https://godoc.org/github.com/stretchr/testify/assert +func (f *F) Assert() *assert.Assertions { + return f.assert +} + +// T returns the *testing.T context +func (f *F) T() *testing.T { + return f.t +} + +// ID returns the current context ID +func (f *F) ID() string { + return f.id +} + +// Set is used to set arbitrary key/values to pass between before/after and test methods +func (f *F) Set(key, val interface{}) { + f.data[key] = val +} + +// Value retrives values set by the F.Set method +func (f *F) Value(key interface{}) interface{} { + return f.data[key] +}