package spec

import (
	"testing"

	. "github.com/onsi/gomega"
	"k8s.io/apimachinery/pkg/api/resource"
)

func TestGetGoMemLimit(t *testing.T) {
	cases := []struct {
		memory string
		limit  string
	}{
		{
			memory: "2Gi",
			limit:  "1448MiB",
		},
		{
			memory: "8Gi",
			limit:  "7372MiB",
		},
		{
			memory: "16Gi",
			limit:  "14745MiB",
		},
		{
			memory: "16G",
			limit:  "13732MiB",
		},
		{
			memory: "16Mi",
			limit:  "14MiB",
		},
		{
			memory: "16M",
			limit:  "13MiB",
		},
		{
			memory: "1024Mi",
			limit:  "424MiB",
		},
	}

	for _, tc := range cases {
		t.Run(tc.memory, func(t *testing.T) {
			g := NewGomegaWithT(t)
			qua, err := resource.ParseQuantity(tc.memory)
			g.Expect(err).To(BeNil())
			g.Expect(GetGoMemLimit(qua, 0.9)).To(Equal(tc.limit))
		})
	}
}
