-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(server): Decompose base URL to URI to helper and add test (#3839)
Decompose the logic for parsing base URL into the URI for client dial. Add a unit test for the new helper.
- Loading branch information
1 parent
0fc8b1b
commit 4cf9582
Showing
2 changed files
with
84 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package repo | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBaseURLToURI(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
baseURL string | ||
expURI string | ||
expErrMsg string | ||
}{ | ||
{ | ||
name: "ipv4", | ||
baseURL: "https://1.2.3.4:5678", | ||
expURI: "1.2.3.4:5678", | ||
expErrMsg: "", | ||
}, | ||
{ | ||
name: "ipv6", | ||
baseURL: "https://[2600:1f14:253f:ef00:87b9::10]:51515", | ||
expURI: "[2600:1f14:253f:ef00:87b9::10]:51515", | ||
expErrMsg: "", | ||
}, | ||
{ | ||
name: "unix https scheme", | ||
baseURL: "unix+https:///tmp/kopia-test606141450/sock", | ||
expURI: "unix:/tmp/kopia-test606141450/sock", | ||
expErrMsg: "", | ||
}, | ||
{ | ||
name: "kopia scheme", | ||
baseURL: "kopia://a:0", | ||
expURI: "a:0", | ||
expErrMsg: "", | ||
}, | ||
{ | ||
name: "unix http scheme is invalid", | ||
baseURL: "unix+http:///tmp/kopia-test606141450/sock", | ||
expURI: "", | ||
expErrMsg: "invalid server address", | ||
}, | ||
{ | ||
name: "invalid address", | ||
baseURL: "a", | ||
expURI: "", | ||
expErrMsg: "invalid server address", | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
gotURI, err := baseURLToURI(tc.baseURL) | ||
if tc.expErrMsg != "" { | ||
require.ErrorContains(t, err, tc.expErrMsg) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
require.Equal(t, tc.expURI, gotURI) | ||
}) | ||
} | ||
} |