package stpolicy

import "testing"

var asp9 = AccessSEPPool{
	SEPID:     9,
	PoolNames: []string{"data03"},
}

var asp7 = AccessSEPPool{
	SEPID:     7,
	PoolNames: []string{"pool_QA"},
}

var asp8 = AccessSEPPool{
	SEPID: 8,
	PoolNames: []string{
		"alpha_pool_block",
		"alpha_pool_stripe",
		"alpha_pool_file",
	},
}

var storagePolicyItems = ListStoragePolicies{
	Data: []ItemStoragePolicy{
		{
			ID:             1,
			GUID:           1,
			Name:           "storagePolicy01",
			Description:    "desc",
			AccessSEPPools: ListAccessSEPPools{asp7},
			Status:         "ENABLED",
			LimitIOPS:      2000,
			Usage:          Usage{},
		},
		{
			ID:             3,
			GUID:           3,
			Name:           "storagePolicy03",
			Description:    "desc",
			AccessSEPPools: ListAccessSEPPools{asp7, asp8, asp9},
			Status:         "ENABLED",
			LimitIOPS:      2500,
			Usage:          Usage{},
		},
		{
			ID:             5,
			GUID:           5,
			Name:           "storagePolicy05",
			Description:    "another desc",
			AccessSEPPools: ListAccessSEPPools{asp8, asp9},
			Status:         "DISABLED",
			LimitIOPS:      2000,
			Usage:          Usage{},
		},
	},
	EntryCount: 3,
}

func TestFilterByID(t *testing.T) {
	actual := storagePolicyItems.FilterByID(1).FindOne()

	if actual.ID != 1 {
		t.Fatal("expected 1 ID, found: ", actual.ID)
	}
}

func TestFilterByName(t *testing.T) {
	actual := storagePolicyItems.FilterByName("storagePolicy01").FindOne()

	if actual.Name != "storagePolicy01" {
		t.Fatal("expected Name 'storagePolicy01', found: ", actual.Name)
	}
}

func TestFilterByStatus(t *testing.T) {
	actual := storagePolicyItems.FilterByStatus("ENABLED")

	if len(actual.Data) != 2 {
		t.Fatal("expected 2 found, actual: ", len(actual.Data))
	}

	for _, item := range actual.Data {
		if item.Status != "ENABLED" {
			t.Fatal("expected Status 'ENABLED', found: ", item.Status)
		}
	}
}

func TestFilterByDesc(t *testing.T) {
	actual := storagePolicyItems.FilterByDesc("desc")

	if len(actual.Data) != 2 {
		t.Fatal("expected 2 found, actual: ", len(actual.Data))
	}

	for _, item := range actual.Data {
		if item.Description != "desc" {
			t.Fatal("expected Description 'desc', found: ", item.Status)
		}
	}
}

func TestFilterByLimitIOPS(t *testing.T) {
	actual := storagePolicyItems.FilterByLimitIOPS(2500).FindOne()

	if actual.LimitIOPS != 2500 {
		t.Fatal("expected LimitIOPS '2500', found: ", actual.LimitIOPS)
	}
}
