// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gke

import (
	"testing"

	gkev1beta1 "github.com/crossplane-contrib/provider-gcp/apis/container/v1beta1"
	"github.com/stretchr/testify/require"

	"github.com/tidbcloud/eks-provider/controllers/tiflow/task/cluster"
	"github.com/tidbcloud/infra-provider/pkg/namer"
)

func TestNodePoolGetSpecTaints(t1 *testing.T) {
	expect := []*gkev1beta1.NodeTaint{
		{Key: namer.LegacyNetworkSelectorKey, Value: "a", Effect: "NO_SCHEDULE"},
		{Key: namer.TiflowClusterSelectorKey, Value: "a", Effect: "NO_SCHEDULE"},
		{Key: namer.TiflowNamespaceSelectorKey, Value: "a", Effect: "NO_SCHEDULE"},
		{Key: namer.TiflowSpecLabelKey, Value: "a", Effect: "NO_SCHEDULE"},
	}
	n := &namer.TiflowNamer{}
	n = n.WithNetworkName("a").
		WithTiflowClusterName("a").
		WithTiflowNamespace("a").
		WithTiflowSpecLabel("a")
	p := &NodePool{
		BaseContext: &cluster.BaseContext{
			Namer: n,
		},
	}
	// we create a map on each call, so test for 5 times to make sure its order is stable
	for i := 0; i < 5; i++ {
		require.Equal(t1, expect, p.getSpecTaints())
	}
}
