package publicconnectionsetting

import (
	"testing"

	"github.com/stretchr/testify/assert"

	globalngv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/nextgen/v1"
)

func TestCvtGlobalToOpenapiPublicConnectionSettingMapsEgressIPs(t *testing.T) {
	got := cvtGlobalToOpenapiPublicConnectionSetting(&globalngv1.PublicConnectionSetting{
		ClusterId: 1001,
		Enable:    boolPtr(true),
		EgressIps: []string{"1.1.1.1", "2.2.2.2"},
	})

	assert.Equal(t, []string{"1.1.1.1", "2.2.2.2"}, got.GetEgressIps())
	assert.True(t, got.GetEnabled())
}

func TestDefaultPublicConnectionSettingHasEmptyEgressIPs(t *testing.T) {
	got := defaultPublicConnectionSetting(1001)

	assert.Empty(t, got.GetEgressIps())
}

func boolPtr(v bool) *bool {
	return &v
}
