package main

import (
	"testing"
	"time"
)

func TestKeyspaceIntervalDefault(t *testing.T) {
	if *keyspaceInterval != time.Second {
		t.Fatalf("expected default keyspace interval to be 1s, got %s", *keyspaceInterval)
	}
}

func TestValidParamRejectsNegativeKeyspaceInterval(t *testing.T) {
	oldOpType := *opType
	oldKeyspaceInterval := *keyspaceInterval
	defer func() {
		*opType = oldOpType
		*keyspaceInterval = oldKeyspaceInterval
	}()

	*keyspaceInterval = -time.Second

	*opType = clean_all_data
	if vaildParam() {
		t.Fatal("clean_all_data with negative keyspace interval should be invalid")
	}

	*opType = archive_ks
	if vaildParam() {
		t.Fatal("archive_ks with negative keyspace interval should be invalid")
	}

	*opType = archive_ks + "," + clean_all_data
	if vaildParam() {
		t.Fatal("combined ops including clean_all_data with negative keyspace interval should be invalid")
	}
}

func TestHasOp(t *testing.T) {
	if !hasOp("archive_ks, clean_all_data", clean_all_data) {
		t.Fatal("expected to find clean_all_data in comma-separated ops")
	}
	if hasOp("archive_ks, clean_region_data", clean_all_data) {
		t.Fatal("did not expect to find clean_all_data")
	}
}
