-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseURL: select port based on schema, plumb through custom httpsPort
Thanks to Christian Schlögl for the report.
- Loading branch information
1 parent
235d00c
commit a645001
Showing
3 changed files
with
68 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package updateflag_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gokrazy/internal/updateflag" | ||
) | ||
|
||
func TestBaseURL(t *testing.T) { | ||
for _, tt := range []struct { | ||
desc string | ||
HTTPPort string | ||
HTTPSPort string | ||
Schema string | ||
Hostname string | ||
Password string | ||
wantURL string | ||
}{ | ||
{ | ||
desc: "default ports", | ||
HTTPPort: "80", | ||
HTTPSPort: "443", | ||
Schema: "http", | ||
Hostname: "bakery", | ||
Password: "secret", | ||
wantURL: "http://gokrazy:secret@bakery/", | ||
}, | ||
|
||
{ | ||
desc: "custom ports (HTTP)", | ||
HTTPPort: "81", | ||
HTTPSPort: "444", | ||
Schema: "http", | ||
Hostname: "bakery", | ||
Password: "secret", | ||
wantURL: "http://gokrazy:secret@bakery:81/", | ||
}, | ||
|
||
{ | ||
desc: "custom ports (HTTPS)", | ||
HTTPPort: "81", | ||
HTTPSPort: "444", | ||
Schema: "https", | ||
Hostname: "bakery", | ||
Password: "secret", | ||
wantURL: "https://gokrazy:secret@bakery:444/", | ||
}, | ||
} { | ||
t.Run(tt.desc, func(t *testing.T) { | ||
updateflag.SetUpdate("yes") | ||
got, err := updateflag.BaseURL(tt.HTTPPort, tt.HTTPSPort, tt.Schema, tt.Hostname, tt.Password) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if got.String() != tt.wantURL { | ||
t.Errorf("BaseURL(<TODO>): got %q, want %q", got, tt.wantURL) | ||
} | ||
}) | ||
} | ||
} |