forked from percona/mongodb_exporter
-
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.
extract whole
buildURI
logic and write a test
- Loading branch information
1 parent
b793c84
commit 1cdf1a6
Showing
2 changed files
with
112 additions
and
12 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 |
---|---|---|
|
@@ -38,3 +38,98 @@ func TestBuildExporter(t *testing.T) { | |
|
||
buildExporter(opts) | ||
} | ||
|
||
func TestBuildURI(t *testing.T) { | ||
const newUser = "xxx" | ||
const newPass = "yyy" | ||
|
||
const originalBareURI = "127.0.0.1" | ||
const originalAuthURI = "usr:[email protected]" | ||
|
||
const originalPrefixBareURI = "mongodb://127.0.0.1" | ||
const originalPrefixAuthURI = "mongodb://usr:[email protected]" | ||
const changedPrefixAuthURI = "mongodb://xxx:[email protected]" | ||
|
||
var newUri string | ||
|
||
t.Log("\nuri with prefix and auth, and auth supplied in opt.User/Password") | ||
newUri = buildURI(originalPrefixAuthURI, newUser, newPass) | ||
t.Logf("Origin: %s", originalPrefixAuthURI) | ||
t.Logf("Expect: %s", originalPrefixAuthURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalPrefixAuthURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with prefix and auth, no auth supplied in opt.User/Password") | ||
newUri = buildURI(originalPrefixAuthURI, "", "") | ||
t.Logf("Origin: %s", originalPrefixAuthURI) | ||
t.Logf("Expect: %s", originalPrefixAuthURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalPrefixAuthURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with no prefix and auth, and auth supplied in opt.User/Password") | ||
newUri = buildURI(originalAuthURI, newUser, newPass) | ||
t.Logf("Origin: %s", originalAuthURI) | ||
t.Logf("Expect: %s", originalAuthURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalAuthURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with no prefix and auth, no auth supplied in opt.User/Password") | ||
newUri = buildURI(originalAuthURI, "", "") | ||
t.Logf("Origin: %s", originalAuthURI) | ||
t.Logf("Expect: %s", originalAuthURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalAuthURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with prefix and no auth, and auth supplied in opt.User/Password") | ||
newUri = buildURI(originalPrefixBareURI, newUser, newPass) | ||
t.Logf("Origin: %s", originalPrefixBareURI) | ||
t.Logf("Expect: %s", changedPrefixAuthURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != changedPrefixAuthURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with prefix and no auth, no auth supplied in opt.User/Password") | ||
newUri = buildURI(originalPrefixBareURI, "", "") | ||
t.Logf("Origin: %s", originalPrefixBareURI) | ||
t.Logf("Expect: %s", originalPrefixBareURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalPrefixBareURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with no prefix and no auth, and auth supplied in opt.User/Password") | ||
newUri = buildURI(originalBareURI, newUser, newPass) | ||
t.Logf("Origin: %s", originalBareURI) | ||
t.Logf("Expect: %s", changedPrefixAuthURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != changedPrefixAuthURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
t.Log("\nuri with no prefix and no auth, no auth supplied in opt.User/Password") | ||
newUri = buildURI(originalBareURI, "", "") | ||
t.Logf("Origin: %s", originalBareURI) | ||
t.Logf("Expect: %s", originalBareURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalBareURI { | ||
t.Fail() | ||
} | ||
newUri = "" | ||
|
||
} |