package http

import (
	"testing"

	. "github.com/onsi/gomega"
)

func Test_GetOrgIdFromPath(t *testing.T) {
	g := NewGomegaWithT(t)
	testCases := []struct {
		url   string
		orgId uint64
		found bool
	}{
		{"/orgs/1234567", 1234567, true},
		{"/api/v1/orgs/1234567", 1234567, true},
		{"/api/v1/projecs/1234567", 0, false},
	}

	for _, tc := range testCases {
		id, found := GetOrgIdFromPath(tc.url)
		g.Expect(id).To(Equal(tc.orgId))
		g.Expect(found).To(Equal(tc.found))
	}
}

func Test_GetProjectIdFromPath(t *testing.T) {
	g := NewGomegaWithT(t)
	testCases := []struct {
		url       string
		projectId uint64
		found     bool
	}{
		{"/orgs/1234567", 0, false},
		{"/api/v1/orgs/1234567/projects/2345678", 2345678, true},
		{"/api/v1/clusters/1234567", 0, false},
	}

	for _, tc := range testCases {
		id, found := GetProjectIdFromPath(tc.url)
		g.Expect(id).To(Equal(tc.projectId))
		g.Expect(found).To(Equal(tc.found))
	}
}

func Test_GetClusterIdFromPath(t *testing.T) {
	g := NewGomegaWithT(t)
	testCases := []struct {
		url       string
		clusterId uint64
		found     bool
	}{
		{"/api/v1/orgs/1234567/projects/2345678", 0, false},
		{"/api/v1/orgs/1234567/clusters/2345678", 2345678, true},
		{"/api/v1/clusters/1234567", 1234567, true},
		{"/api/v1/serverless/orgs/1234567/recycledInstances/2345678", 2345678, true},
		{"/api/v1/serverless/orgs/1234567/recycledInstances", 0, false},
	}

	for _, tc := range testCases {
		id, found := GetClusterIdFromPath(tc.url)
		g.Expect(id).To(Equal(tc.clusterId))
		g.Expect(found).To(Equal(tc.found))
	}
}
