Skip to content

Commit

Permalink
Merge pull request #36 from atlanhq/DVX-482-truncate-the-part-of-the-…
Browse files Browse the repository at this point in the history
…url-after-com-co-etc-in-the-base-url

Chore: Add test for `NormalizedURL` and fix existing test cases.
  • Loading branch information
0xquark authored Jun 6, 2024
2 parents 0aa45a7 + 7040f52 commit b871bc8
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions atlan/assets/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func TestEnvConfig(t *testing.T) {

// Assert API key and base URL are correctly set
assert.Equal(t, "your_api_key", DefaultAtlanClient.ApiKey)
assert.Equal(t, "your_base_url", DefaultAtlanClient.host)
assert.Equal(t, "https://your_base_url", DefaultAtlanClient.host)
}

func TestEnvConfigUsingContext(t *testing.T) {
// Set up environment variables
apiKey := "your_api_key"
baseURL := "your_base_url"
baseURL := "https://your_base_url"

// Initialize client
ctx, err := Context(baseURL, apiKey)
Expand All @@ -50,6 +50,33 @@ func TestEnvConfigUsingContext(t *testing.T) {
assert.Equal(t, baseURL, ctx.host)
}

func TestContextWithNormalizedURL(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"devx9.atlan.com", "https://devx9.atlan.com"},
{"https://devx9.atlan.com", "https://devx9.atlan.com"},
{"devx9.atlan.com/some/path", "https://devx9.atlan.com"},
{"devx9.atlan.com?query=param", "https://devx9.atlan.com"},
{"https://devx9.atlan.com/some/path", "https://devx9.atlan.com"},
}

apiKey := "your_api_key"

for _, test := range tests {
t.Run(test.input, func(t *testing.T) {
// Initialize client context with the test input
ctx, err := Context(test.input, apiKey)

assert.NoError(t, err)

// Ensure the base URL is normalized correctly
assert.Equal(t, test.expected, ctx.host)
})
}
}

func TestLoggerConfig(t *testing.T) {
ctx, _ := Context("api_key", "baseurl")

Expand Down

0 comments on commit b871bc8

Please sign in to comment.