-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up test helper functions (#544)
Reduce duplication in tests and consistent messages for skipped integration tests.
- Loading branch information
Showing
14 changed files
with
139 additions
and
151 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,36 @@ | ||
// Helper package that should only be used in test files | ||
package dbtest | ||
|
||
import ( | ||
"net/url" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// MustParseURL parses a URL from string, and fails the test if the URL is invalid. | ||
func MustParseURL(t *testing.T, s string) *url.URL { | ||
require.NotEmpty(t, s) | ||
|
||
u, err := url.Parse(s) | ||
require.NoError(t, err) | ||
|
||
return u | ||
} | ||
|
||
// GetenvOrSkip gets an environment variable, and skips the test if it is empty. | ||
func GetenvOrSkip(t *testing.T, key string) string { | ||
value := os.Getenv(key) | ||
if value == "" { | ||
t.Skipf("no %s provided", key) | ||
} | ||
|
||
return value | ||
} | ||
|
||
// GetenvURLOrSkip gets an environment variable, parses it as a URL, | ||
// fails the test if the URL is invalid, and skips the test if empty. | ||
func GetenvURLOrSkip(t *testing.T, key string) *url.URL { | ||
return MustParseURL(t, GetenvOrSkip(t, key)) | ||
} |
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.