package task

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestGetNodePoolName(t *testing.T) {
	bt := &baseTask{Context: &Context{}}

	tests := map[string]struct {
		instanceType string
		k8sName      string
		k8sVersion   string
		want         string
	}{
		"x86 instance type with dots normalised": {
			instanceType: "m5.large",
			k8sName:      "eks-cluster-1",
			k8sVersion:   "1.32",
			want:         "compact-m5-large-eks-cluster-1-132",
		},
		"arm instance type with multiple dots normalised": {
			instanceType: "trn1n.32xlarge",
			k8sName:      "eks-cluster-1",
			k8sVersion:   "1.28",
			want:         "compact-trn1n-32xlarge-eks-cluster-1-128",
		},
		"instance type with underscores normalised": {
			instanceType: "Standard_E104ids_v5",
			k8sName:      "aks-cluster-us",
			k8sVersion:   "1.29",
			want:         "compact-Standard-E104ids-v5-aks-cluster-us-129",
		},
		"long k8s name is hashed to keep result within 63 chars": {
			instanceType: "m5.large",
			k8sName:      "very-long-eks-cluster-name-exceeding-identity-limit",
			k8sVersion:   "1.32",
			want:         "compact-m5-large-very-long-eks-cluster-name-exceed-60e8fc83-132",
		},
	}

	for name, tt := range tests {
		t.Run(name, func(t *testing.T) {
			got := bt.getNodePoolName(tt.instanceType, tt.k8sName, tt.k8sVersion)
			assert.Equal(t, tt.want, got)
			assert.LessOrEqual(t, len(got), 63, "nodepool name must not exceed 63 chars")
		})
	}
}
