Esempio n. 1
0
func (m *Mock) Execute(p *neat.Playbook) (interface{}, neat.ModuleStatus, error) {
	if m.v != nil {
		switch v := m.v.(type) {
		case error:
			me := neat.ModuleE{Module: m}
			return me.Fail(v.Error())
		case neat.ModuleStatus:
			return nil, v, nil
		default:
			panic(v)
		}
	}
	return nil, neat.ModuleOk, nil
}
Esempio n. 2
0
func TestModuleE_Fail(t *testing.T) {
	registry := &neat.ModuleRegistry{}
	registry.Register("mock", &MockFactory{})

	m := neat.ModuleE{Module: registry.MustCreate("mock")}
	result, status, err := m.Fail("module failed to run")
	if result != nil {
		t.Errorf("expected result to be nil, got %v", result)
	}
	if status != neat.ModuleFailed {
		t.Errorf("expected status to be %s, got %s", neat.ModuleFailed, status)
	}
	if err == nil || err.Error() != "module failed to run" {
		t.Errorf("expected error to be 'module failed to run', got '%s'", err)
	}
}
Esempio n. 3
0
func TestModuleE_Ok(t *testing.T) {
	registry := &neat.ModuleRegistry{}
	registry.Register("mock", &MockFactory{})

	m := neat.ModuleE{Module: registry.MustCreate("mock")}
	result, status, err := m.Ok("module succeeded")
	actual, ok := result.(string)
	if !ok || actual != "module succeeded" {
		t.Errorf("expected result to be 'module succeded', got '%v'", result)
	}
	if status != neat.ModuleOk {
		t.Errorf("expected status to be %s, got %s", neat.ModuleOk, status)
	}
	if err != nil {
		t.Error(err)
	}
}