package model

import (
	"testing"

	"github.com/tidbcloud/pov-service/internal/common/constant"
	"github.com/stretchr/testify/assert"
)

func TestWorkloadTest_GetDurationMinConf(t *testing.T) {
	tests := []struct {
		name     string
		params   WorkloadParams
		expected int
		ok       bool
	}{
		{
			name:     "param not found",
			params:   WorkloadParams{},
			expected: 0,
			ok:       false,
		},
		{
			name: "param is int",
			params: WorkloadParams{
				{Name: string(constant.Duration), Value: "60"},
			},
			expected: 60,
			ok:       true,
		},
		// {
		// 	name: "param is float64",
		// 	params: WorkloadParams{
		// 		{Name: string(constant.Duration), Value: "120.0"},
		// 	},
		// 	expected: 120,
		// 	ok:       true,
		// },
		{
			name: "param is string convertible to int",
			params: WorkloadParams{
				{Name: string(constant.Duration), Value: "180"},
			},
			expected: 180,
			ok:       true,
		},
		{
			name: "param is string not convertible to int",
			params: WorkloadParams{
				{Name: string(constant.Duration), Value: "abc"},
			},
			expected: 0,
			ok:       false,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			w := WorkloadTest{
				Params: tt.params,
			}
			value, ok := w.GetDurationMinConf()
			assert.Equal(t, tt.expected, value)
			assert.Equal(t, tt.ok, ok)
		})
	}
}
