|  | 
|  | 1 | +package status | 
|  | 2 | + | 
|  | 3 | +import ( | 
|  | 4 | +	"testing" | 
|  | 5 | + | 
|  | 6 | +	"github.com/bivas/rivi/mocks" | 
|  | 7 | +	"github.com/bivas/rivi/types" | 
|  | 8 | +	"github.com/bivas/rivi/util/state" | 
|  | 9 | +	"github.com/stretchr/testify/assert" | 
|  | 10 | +) | 
|  | 11 | + | 
|  | 12 | +func TestSerialization(t *testing.T) { | 
|  | 13 | +	input := map[string]interface{}{ | 
|  | 14 | +		"state":       "Success", | 
|  | 15 | +		"description": "this is a test", | 
|  | 16 | +	} | 
|  | 17 | + | 
|  | 18 | +	var f factory | 
|  | 19 | +	result := f.BuildAction(input) | 
|  | 20 | +	assert.NotNil(t, result, "should create action") | 
|  | 21 | +	s, ok := result.(*action) | 
|  | 22 | +	assert.True(t, ok, "should be of this package") | 
|  | 23 | +	assert.Equal(t, "Success", s.rule.State, "state") | 
|  | 24 | +	assert.Equal(t, "this is a test", s.rule.Description, "desc") | 
|  | 25 | +} | 
|  | 26 | + | 
|  | 27 | +func TestSetDefaultStatus(t *testing.T) { | 
|  | 28 | +	input := map[string]interface{}{ | 
|  | 29 | +		"description": "TestSetDefaultStatus", | 
|  | 30 | +	} | 
|  | 31 | +	var f factory | 
|  | 32 | +	action := f.BuildAction(input) | 
|  | 33 | +	assert.NotNil(t, action, "should create action") | 
|  | 34 | +	meta := &mocks.MockData{} | 
|  | 35 | +	config := &mocks.MockConfiguration{} | 
|  | 36 | +	action.Apply(state.New(config, meta)) | 
|  | 37 | +	assert.Equal(t, types.GetState(defaultState), meta.StatusState, "state") | 
|  | 38 | +	assert.Equal(t, "TestSetDefaultStatus", meta.StatusDescription, "desc") | 
|  | 39 | +} | 
|  | 40 | + | 
|  | 41 | +func TestSetUnknownStatus(t *testing.T) { | 
|  | 42 | +	input := map[string]interface{}{ | 
|  | 43 | +		"state":       "TestSetUnknownStatus", | 
|  | 44 | +		"description": "TestSetUnknownStatus", | 
|  | 45 | +	} | 
|  | 46 | +	var f factory | 
|  | 47 | +	action := f.BuildAction(input) | 
|  | 48 | +	assert.NotNil(t, action, "should create action") | 
|  | 49 | +	meta := &mocks.MockData{} | 
|  | 50 | +	config := &mocks.MockConfiguration{} | 
|  | 51 | +	action.Apply(state.New(config, meta)) | 
|  | 52 | +	assert.Equal(t, types.GetState(unknownState), meta.StatusState, "state") | 
|  | 53 | +	assert.Equal(t, "TestSetUnknownStatus", meta.StatusDescription, "desc") | 
|  | 54 | +} | 
|  | 55 | + | 
|  | 56 | +func TestSetSuccessStatus(t *testing.T) { | 
|  | 57 | +	input := map[string]interface{}{ | 
|  | 58 | +		"state":       "Success", | 
|  | 59 | +		"description": "TestSetSuccessStatus", | 
|  | 60 | +	} | 
|  | 61 | +	var f factory | 
|  | 62 | +	action := f.BuildAction(input) | 
|  | 63 | +	assert.NotNil(t, action, "should create action") | 
|  | 64 | +	meta := &mocks.MockData{} | 
|  | 65 | +	config := &mocks.MockConfiguration{} | 
|  | 66 | +	action.Apply(state.New(config, meta)) | 
|  | 67 | +	assert.Equal(t, types.Success, meta.StatusState, "state") | 
|  | 68 | +	assert.Equal(t, "TestSetSuccessStatus", meta.StatusDescription, "desc") | 
|  | 69 | +} | 
|  | 70 | + | 
|  | 71 | +func TestDefault(t *testing.T) { | 
|  | 72 | +	input := map[string]interface{}{} | 
|  | 73 | +	var f factory | 
|  | 74 | +	action := f.BuildAction(input) | 
|  | 75 | +	assert.NotNil(t, action, "should create action") | 
|  | 76 | +	meta := &mocks.MockData{} | 
|  | 77 | +	config := &mocks.MockConfiguration{} | 
|  | 78 | +	action.Apply(state.New(config, meta)) | 
|  | 79 | +	assert.Equal(t, types.GetState(defaultState), meta.StatusState, "state") | 
|  | 80 | +	assert.Equal(t, defaultDescription, meta.StatusDescription, "desc") | 
|  | 81 | +} | 
0 commit comments