|
8 | 8 | "net/http"
|
9 | 9 | "testing"
|
10 | 10 |
|
| 11 | + "github.com/go-openapi/runtime/client" |
11 | 12 | "github.com/stretchr/testify/assert"
|
12 | 13 | "github.com/stretchr/testify/require"
|
13 | 14 | )
|
@@ -73,3 +74,35 @@ func TestExtractGrafanaInfoFromHeaders(t *testing.T) {
|
73 | 74 | assert.Equal(t, "my-test-api-key", apiKey)
|
74 | 75 | })
|
75 | 76 | }
|
| 77 | + |
| 78 | +func TestExtractGrafanaClientPath(t *testing.T) { |
| 79 | + t.Run("no custom path", func(t *testing.T) { |
| 80 | + t.Setenv("GRAFANA_URL", "http://my-test-url.grafana.com/") |
| 81 | + ctx := ExtractGrafanaClientFromEnv(context.Background()) |
| 82 | + |
| 83 | + c := GrafanaClientFromContext(ctx) |
| 84 | + require.NotNil(t, c) |
| 85 | + rt := c.Transport.(*client.Runtime) |
| 86 | + assert.Equal(t, "/api", rt.BasePath) |
| 87 | + }) |
| 88 | + |
| 89 | + t.Run("custom path", func(t *testing.T) { |
| 90 | + t.Setenv("GRAFANA_URL", "http://my-test-url.grafana.com/grafana") |
| 91 | + ctx := ExtractGrafanaClientFromEnv(context.Background()) |
| 92 | + |
| 93 | + c := GrafanaClientFromContext(ctx) |
| 94 | + require.NotNil(t, c) |
| 95 | + rt := c.Transport.(*client.Runtime) |
| 96 | + assert.Equal(t, "/grafana/api", rt.BasePath) |
| 97 | + }) |
| 98 | + |
| 99 | + t.Run("custom path, trailing slash", func(t *testing.T) { |
| 100 | + t.Setenv("GRAFANA_URL", "http://my-test-url.grafana.com/grafana/") |
| 101 | + ctx := ExtractGrafanaClientFromEnv(context.Background()) |
| 102 | + |
| 103 | + c := GrafanaClientFromContext(ctx) |
| 104 | + require.NotNil(t, c) |
| 105 | + rt := c.Transport.(*client.Runtime) |
| 106 | + assert.Equal(t, "/grafana/api", rt.BasePath) |
| 107 | + }) |
| 108 | +} |
0 commit comments