func TestCronOutputInSortedOrder(t *testing.T) {
	fname := "/tmp/chaoscron"
	err := EnsureFileAbsent(fname)
	if err != nil {
		t.Fatal(err.Error())
	}
	config := config.Defaults()
	config.Set(param.Enabled, true)
	config.Set(param.CronPath, fname)
	config.Set(param.Accounts, []string{"prod"})
	schedule := schedule.New()
	addToSchedule(t, schedule, "2015-10-01T11:23:00-07:00", newClusterGroup("abc", "prod", "abc-prod", "us-east-1"))
	addToSchedule(t, schedule, "2015-10-01T10:15:00-07:00", newClusterGroup("abc", "prod", "abc-prod", "us-west-2"))
	err = registerWithCron(schedule, config)
	if err != nil {
		t.Fatal(err.Error())
	}
	dat, err := ioutil.ReadFile(fname)
	if err != nil {
		t.Error(err.Error())
		return
	}
	actual := string(dat)
	expected := `15 17 1 10 4 root /apps/chaosmonkey/chaosmonkey-terminate.sh abc prod --cluster=abc-prod --region=us-west-2
23 18 1 10 4 root /apps/chaosmonkey/chaosmonkey-terminate.sh abc prod --cluster=abc-prod --region=us-east-1
`
	if actual != expected {
		t.Errorf("\nExpected:\n%s\nActual:\n%s", expected, actual)
	}
}
same as TestRegisterWithCron, but reverses the order that
things are added to schedule.
package command
import (
	"io/ioutil"
	"testing"
	"time"
	"github.com/Netflix/chaosmonkey/config"
	"github.com/Netflix/chaosmonkey/config/param"
	"github.com/Netflix/chaosmonkey/grp"
	"github.com/Netflix/chaosmonkey/schedule"
)
func addToSchedule(t *testing.T, sched *schedule.Schedule, timeString string, group grp.InstanceGroup) {
	tm, err := time.Parse(time.RFC3339, timeString)
	if err != nil {
		t.Fatal("Could not parse time string:", tm, err.Error())
	}
	sched.Add(tm, group)
}
func newClusterGroup(app, account, cluster, region string) grp.InstanceGroup {
	return grp.New(app, account, region, "", cluster)
}
func TestRegisterWithCron(t *testing.T) {
	fname := "/tmp/chaoscron"
	err := EnsureFileAbsent(fname)
	if err != nil {
		t.Error(err.Error())
		return
	}
	config := config.Defaults()
	config.Set(param.Enabled, true)
	config.Set(param.CronPath, fname)
	config.Set(param.Accounts, []string{"prod"})
	sched := schedule.New()
	addToSchedule(t, sched, "2015-10-01T10:15:00-07:00", newClusterGroup("abc", "prod", "abc-prod", "us-east-1"))
	addToSchedule(t, sched, "2015-10-01T11:23:00-07:00", newClusterGroup("abc", "prod", "abc-prod", "us-west-2"))
	err = registerWithCron(sched, config)
	if err != nil {
		t.Fatal(err.Error())
	}
	dat, err := ioutil.ReadFile(fname)
	if err != nil {
		t.Error(err.Error())
		return
	}
	actual := string(dat)
	expected := `15 17 1 10 4 root /apps/chaosmonkey/chaosmonkey-terminate.sh abc prod --cluster=abc-prod --region=us-east-1
23 18 1 10 4 root /apps/chaosmonkey/chaosmonkey-terminate.sh abc prod --cluster=abc-prod --region=us-west-2
`
	if actual != expected {
		t.Errorf("\nExpected:\n%s\nActual:\n%s", expected, actual)
	}
}