-
Notifications
You must be signed in to change notification settings - Fork 10
integration test hostname changed to local IP #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bubylou
wants to merge
6
commits into
vanadium23:main
Choose a base branch
from
bubylou:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
040ce5f
integration test hostname changed to local IP
bubylou 5d3de92
environment variables for test options
bubylou 1187918
swap test creds to env var
bubylou 08b2d36
clean up unused variables
bubylou 864692f
only set creds on empty username
bubylou cbd717f
cleanup code
bubylou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,17 +18,11 @@ import ( | |
| petname "github.com/dustinkirkland/golang-petname" | ||
| ) | ||
|
|
||
| const ( | ||
| // Attempts connection | ||
| host = "app:8080" | ||
| healthPath = "http://" + host + "/healthcheck" | ||
| attempts = 20 | ||
|
|
||
| // HTTP REST | ||
| basePath = "http://" + host | ||
| ) | ||
| const attempts = 20 | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| host, _, _ := grabTestHost() | ||
|
|
||
| err := healthCheck(attempts) | ||
| if err != nil { | ||
| log.Fatalf("Integration tests: host %s is not available: %s", host, err) | ||
|
|
@@ -42,6 +36,7 @@ func TestMain(m *testing.M) { | |
|
|
||
| func healthCheck(attempts int) error { | ||
| var err error | ||
| _, healthPath, _ := grabTestHost() | ||
|
|
||
| for attempts > 0 { | ||
| err = Do(Get(healthPath), Expect().Status().Equal(http.StatusOK)) | ||
|
|
@@ -60,6 +55,8 @@ func healthCheck(attempts int) error { | |
| } | ||
|
|
||
| func TestWebFooterVersion(t *testing.T) { | ||
| _, _, basePath := grabTestHost() | ||
|
|
||
| Test(t, | ||
| Description("Footer Version"), | ||
| Get(basePath+"/"), | ||
|
|
@@ -72,6 +69,7 @@ func TestWebFooterVersion(t *testing.T) { | |
| // New tests based on controller/web | ||
| // login/page | ||
| func TestWebAuthUser(t *testing.T) { | ||
| _, _, basePath := grabTestHost() | ||
| username, password := grabTestUser() | ||
|
|
||
| Test(t, | ||
|
|
@@ -116,6 +114,7 @@ func TestWebAuthUser(t *testing.T) { | |
| // devices | ||
| func TestWebDevice(t *testing.T) { | ||
| client, loginSteps := webAuthSteps() | ||
| _, _, basePath := grabTestHost() | ||
|
|
||
| Test(t, | ||
| Description("Login for Device"), | ||
|
|
@@ -178,6 +177,7 @@ func TestHTTPKoreaderSyncProgress(t *testing.T) { | |
| deviceName := generateDeviceName() | ||
| deviceSteps := setupDeviceSteps(client, deviceName) | ||
| Test(t, Description("Device Register"), deviceSteps) | ||
| _, _, basePath := grabTestHost() | ||
|
|
||
| // check auth | ||
| Test(t, | ||
|
|
@@ -218,6 +218,7 @@ func TestHTTPKoreaderSyncProgress(t *testing.T) { | |
| // HTTP GET /users/auth | ||
| func TestHTTPAuth(t *testing.T) { | ||
| username, password := grabTestUser() | ||
| _, _, basePath := grabTestHost() | ||
| Test(t, | ||
| Description("Auth With Incorrect Password"), | ||
| Get(basePath+"/users/auth"), | ||
|
|
@@ -275,6 +276,7 @@ func TestHTTPKompanionShelf(t *testing.T) { | |
|
|
||
| client, loginSteps := webAuthSteps() | ||
| Test(t, Description("Login for Device"), loginSteps) | ||
| _, _, basePath := grabTestHost() | ||
|
|
||
| // put book | ||
| var redirectedPath string | ||
|
|
@@ -353,6 +355,7 @@ func TestWebStats(t *testing.T) { | |
| Test(t, Description("Device Register"), deviceSteps) | ||
|
|
||
| basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(deviceName+":"+password)) | ||
| _, _, basePath := grabTestHost() | ||
|
|
||
| statsContent, err := os.ReadFile("../test/test_data/koreader/koreader_statistics_example.sqlite3") | ||
| if err != nil { | ||
|
|
@@ -420,6 +423,7 @@ func TestHTTPKompanionOPDS(t *testing.T) { | |
|
|
||
| client, loginSteps := webAuthSteps() | ||
| Test(t, Description("Login for Device"), loginSteps) | ||
| _, _, basePath := grabTestHost() | ||
|
|
||
| // put book | ||
| var redirectedPath string | ||
|
|
@@ -461,9 +465,34 @@ func TestHTTPKompanionOPDS(t *testing.T) { | |
| // seach opds | ||
| } | ||
|
|
||
| func grabTestUser() (string, string) { | ||
| // TODO: read from env | ||
| return "user", "password" | ||
| func readPrefixedEnv(key string) string { | ||
| envKey := fmt.Sprintf("KOMPANION_%s", strings.ToUpper(key)) | ||
| return os.Getenv(envKey) | ||
| } | ||
|
|
||
| func grabTestHost() (host string, healthPath string, basePath string) { | ||
| host = readPrefixedEnv("TEST_HOST") | ||
|
|
||
| if host == "" { | ||
| host = "app:8080" | ||
| } | ||
|
|
||
| healthPath = "http://" + host + "/healthcheck" | ||
| basePath = "http://" + host | ||
|
|
||
| return host, healthPath, basePath | ||
| } | ||
|
|
||
| func grabTestUser() (user string, password string) { | ||
| user = readPrefixedEnv("TEST_USER") | ||
| password = readPrefixedEnv("TEST_PASSWORD") | ||
|
|
||
| if user == "" || password == "" { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it needs to be something like:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| user = "user" | ||
| password = "password" | ||
| } | ||
|
|
||
| return user, password | ||
| } | ||
|
|
||
| func generateDeviceName() string { | ||
|
|
@@ -477,6 +506,7 @@ func hashSyncPassword(password string) string { | |
|
|
||
| // webAuthSteps returns a client and a step to authenticate | ||
| func webAuthSteps() (*http.Client, hit.IStep) { | ||
| _, _, basePath := grabTestHost() | ||
| username, password := grabTestUser() | ||
|
|
||
| jar, err := cookiejar.New(nil) | ||
|
|
@@ -505,6 +535,7 @@ func webAuthSteps() (*http.Client, hit.IStep) { | |
| } | ||
|
|
||
| func setupDeviceSteps(client *http.Client, deviceName string) hit.IStep { | ||
| _, _, basePath := grabTestHost() | ||
| return CombineSteps( | ||
| HTTPClient(client), | ||
| Description("Device Register"), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.