package secgroup

import "testing"

var securityGroups = ListSecurityGroups{
	Data: []ItemSecurityGroup{
		{
			ID:          1,
			AccountID:   1,
			Name:        "sg1",
			Description: "some desc",
			CreatedBy:   "user",
		},
		{
			ID:          3,
			AccountID:   3,
			Name:        "sg3",
			Description: "some desc",
			CreatedBy:   "anotheruser",
		},
		{
			ID:          5,
			AccountID:   3,
			Name:        "sg5",
			Description: "some other desc",
			CreatedBy:   "anotheruser",
			UpdatedBy:   "user",
		},
	},
	EntryCount: 3,
}

func TestFilterByID(t *testing.T) {
	actual := securityGroups.FilterByID(1).FindOne()
	if actual.ID != 1 {
		t.Fatal("expected ID 1, found: ", actual.ID)
	}
}

func TestFilterByName(t *testing.T) {
	actual := securityGroups.FilterByName("sg3").FindOne()
	if actual.Name != "sg3" {
		t.Fatal("expected Name sg3, found: ", actual.Name)
	}
}

func TestFilterByDescription(t *testing.T) {
	actual := securityGroups.FilterByDescription("some desc")

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

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

func TestFilterByAccountID(t *testing.T) {
	actual := securityGroups.FilterByAccountID(1).FindOne()
	if actual.AccountID != 1 {
		t.Fatal("expected AccountID 1, found: ", actual.AccountID)
	}
}

func TestFilterByCreatedBy(t *testing.T) {
	actual := securityGroups.FilterByCreatedBy("anotheruser")

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

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

func TestFilterByUpdatedBy(t *testing.T) {
	actual := securityGroups.FilterByUpdatedBy("user").FindOne()
	if actual.UpdatedBy != "user" {
		t.Fatal("expected UpdatedBy 'user', found: ", actual.UpdatedBy)
	}
}
