package tests

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/validator"
)

func TestCANBusValidator(t *testing.T) {
	bus := common.CANBus{
		MemBuffSize:  -20,
		DiskBuffSize: -20,
	}

	err := validator.ValidateStruct(bus)
	if err == nil {
		t.Fail()
		t.Log("No negative MemBuffSize of DiskBuffSize not enforced")
	}

	bus = common.CANBus{
		Enabled:      false,
		MemBuffSize:  0,
		DiskBuffSize: 0,
	}
	err = validator.ValidateStruct(bus)
	if err != nil {
		t.Fail()
		t.Log("Failed with enabled false, and mem & disk buff at 0")
	}

	bus = common.CANBus{
		Enabled:      true,
		MemBuffSize:  16777216,
		DiskBuffSize: 1073741824,
	}
	err = validator.ValidateStruct(bus)
	if err != nil {
		t.Fail()
		t.Log("Failed with enabled true, and mem & disk buff at minimum default")
	}

	bus = common.CANBus{
		Enabled:      true,
		MemBuffSize:  16777216000000,
		DiskBuffSize: 10737418240000000,
	}
	err = validator.ValidateStruct(bus)
	if err == nil {
		t.Fail()
		t.Log("Expected Fail with enabled true, and mem & disk buff at very big numbers")
	}
}
