1package framework 2 3import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/helper/uuid" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9) 10 11// F is the framework context that is passed to each test. 12// It is used to access the *testing.T context as well as testify helpers 13type F struct { 14 id string 15 *require.Assertions 16 assert *assert.Assertions 17 t *testing.T 18 19 data map[interface{}]interface{} 20} 21 22func newF(t *testing.T) *F { 23 return newFWithID(uuid.Generate()[:8], t) 24} 25 26func newFFromParent(f *F, t *testing.T) *F { 27 child := newF(t) 28 for k, v := range f.data { 29 child.Set(k, v) 30 } 31 return child 32} 33 34func newFWithID(id string, t *testing.T) *F { 35 ft := &F{ 36 id: id, 37 t: t, 38 Assertions: require.New(t), 39 assert: assert.New(t), 40 } 41 42 return ft 43} 44 45// Assert fetches an assert flavor of testify assertions 46// https://godoc.org/github.com/stretchr/testify/assert 47func (f *F) Assert() *assert.Assertions { 48 return f.assert 49} 50 51// T returns the *testing.T context 52func (f *F) T() *testing.T { 53 return f.t 54} 55 56// ID returns the current context ID 57func (f *F) ID() string { 58 return f.id 59} 60 61// Set is used to set arbitrary key/values to pass between before/after and test methods 62func (f *F) Set(key, val interface{}) { 63 f.data[key] = val 64} 65 66// Value retrives values set by the F.Set method 67func (f *F) Value(key interface{}) interface{} { 68 return f.data[key] 69} 70