package rules

import (
	"iwarma.ru/console/correlator/events"
	"testing"
)

func TestActionTestErrors(t *testing.T) {
	action := TestAction{
		PerformError:        true,
		ParseInterfaceError: true,
		MarshalError:        true,
		UnmarshalError:      true,
	}

	eventsArray := make([]*events.Event, 0)

	err := action.Perform(&eventsArray)
	if err == nil {
		t.Error("Got error in Perform")
	}

	err = action.ParseInterface("test")
	if err == nil {
		t.Error("Got error in ParseInterface")
	}

	bytes, err := action.MarshalJSON()
	if err == nil {
		t.Error("Got error in MarshalJSON")
	}

	err = action.UnmarshalJSON(bytes)
	if err == nil {
		t.Error("Got error in UnmarshalJSON")
	}
}

func TestActionTestNoErrors(t *testing.T) {
	action := TestAction{
		PerformError:        false,
		ParseInterfaceError: false,
		MarshalError:        false,
		UnmarshalError:      false,
	}

	eventsArray := make([]*events.Event, 0)

	err := action.Perform(&eventsArray)
	if err != nil {
		t.Error("Got error in Perform")
	}

	err = action.ParseInterface("test")
	if err != nil {
		t.Error("Got error in ParseInterface")
	}

	bytes, err := action.MarshalJSON()
	if err != nil {
		t.Error("Got error in MarshalJSON")
	}

	err = action.UnmarshalJSON(bytes)
	if err != nil {
		t.Error("Got error in UnmarshalJSON")
	}
}
