package regionalapi

import (
	"testing"

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

func TestBuildRegionalURI(t *testing.T) {
	testcases := []struct {
		regionalAddr string
		uriPath      string
		err          bool
		expectedURI  string
	}{
		{
			regionalAddr: "abc",
			uriPath:      "def",
			err:          true,
			expectedURI:  "",
		},
		{
			regionalAddr: "http://abc.com",
			uriPath:      "def",
			err:          false,
			expectedURI:  "http://abc.com/def",
		},
		{
			regionalAddr: "http://abc.com/",
			uriPath:      "/def/",
			err:          false,
			expectedURI:  "http://abc.com/def/",
		},
		{
			regionalAddr: "https://abc.com",
			uriPath:      "def",
			err:          false,
			expectedURI:  "https://abc.com/def",
		},
		{
			regionalAddr: "https://abc.com/",
			uriPath:      "/def/",
			err:          false,
			expectedURI:  "https://abc.com/def/",
		},
		{
			regionalAddr: "https://abc.com/",
			uriPath:      "/{ticdc_cluster_id}:scale",
			err:          false,
			expectedURI:  "https://abc.com/{ticdc_cluster_id}:scale",
		},
	}

	for _, tc := range testcases {
		uri, err := buildRegionalURI(tc.regionalAddr, tc.uriPath)
		if tc.err {
			assert.Error(t, err)
		} else {
			assert.NoError(t, err)
			assert.Equal(t, tc.expectedURI, uri)
		}
	}
}
