mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
826245f511
Avoid building GMS base path when provided
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package gmsclient
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_buildBasePath(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Domain is required
|
|
_, err := NewGMSClient(&setting.Cfg{
|
|
CloudMigration: setting.CloudMigrationSettings{
|
|
GMSDomain: "",
|
|
},
|
|
})
|
|
require.Error(t, err)
|
|
|
|
// Domain is required
|
|
c, err := NewGMSClient(&setting.Cfg{
|
|
CloudMigration: setting.CloudMigrationSettings{
|
|
GMSDomain: "non-empty",
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
client := c.(*gmsClientImpl)
|
|
|
|
tests := []struct {
|
|
description string
|
|
domain string
|
|
clusterSlug string
|
|
expected string
|
|
}{
|
|
{
|
|
description: "domain starts with http://, should return domain",
|
|
domain: "http://some-domain:8080",
|
|
clusterSlug: "anything",
|
|
expected: "http://some-domain:8080",
|
|
},
|
|
{
|
|
description: "domain starts with https://, should return domain",
|
|
domain: "https://some-domain:8080",
|
|
clusterSlug: "anything",
|
|
expected: "https://some-domain:8080",
|
|
},
|
|
{
|
|
description: "domain doesn't start with http or https, should build a string using the domain and clusterSlug",
|
|
domain: "gms-dev",
|
|
clusterSlug: "us-east-1",
|
|
expected: "https://cms-us-east-1.gms-dev/cloud-migrations",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.description, func(t *testing.T) {
|
|
client.cfg.CloudMigration.GMSDomain = tt.domain
|
|
assert.Equal(t, tt.expected, client.buildBasePath(tt.clusterSlug))
|
|
})
|
|
}
|
|
}
|