forked from redpanda-data/terraform-provider-redpanda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move cluster_api_url parsing out of Terraform lifecycle path
If a Cluster or ServerlessCluster returns a URL that can't be parsed, it shouldn't be an error for that resource or taint the state. This commit moves the parsing into cloud.SpawnConn instead, so an unparseable URL will only affect downstream resources that try to use it.
- Loading branch information
1 parent
bfcd753
commit 3856ba4
Showing
13 changed files
with
123 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package cloud | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestParseHTTPSURLAsGrpc(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
url string | ||
expected string | ||
expectError bool | ||
}{ | ||
{ | ||
name: "URL with incorrect scheme", | ||
url: "http://example.com:8080", | ||
expected: "", | ||
expectError: true, | ||
}, | ||
{ | ||
name: "URL with scheme, no port", | ||
url: "https://example.com", | ||
expected: "example.com", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "URL without scheme, with port", | ||
url: "example.com:9090", | ||
expected: "example.com:9090", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "URL without scheme, no port", | ||
url: "example.com", | ||
expected: "example.com", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "IP address with port", | ||
url: "192.168.1.1:8080", | ||
expected: "192.168.1.1:8080", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "IP address without port", | ||
url: "192.168.1.1", | ||
expected: "192.168.1.1", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "URL with trailing slash", | ||
url: "example.com/", | ||
expected: "example.com", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "URL with trailing path", | ||
url: "example.com/api/v1", | ||
expected: "", | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Empty URL", | ||
url: "", | ||
expected: "", | ||
expectError: true, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result, err := parseHTTPSURLAsGrpc(tc.url) | ||
if tc.expectError { | ||
if err == nil { | ||
t.Errorf("Expected an error, but got none") | ||
} | ||
} else { | ||
if err != nil { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
if result != tc.expected { | ||
t.Errorf("Expected %q, but got %q", tc.expected, result) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.