-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for BAZELISK_FORMAT_URL
This new configuration setting provides a format-like string to compute the URL from which to fetch Bazel. Takes precedence over BAZELISK_BASE_URL as this is a more general concept. Fixes #423.
- Loading branch information
Showing
9 changed files
with
217 additions
and
38 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
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,63 @@ | ||
package core | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/bazelbuild/bazelisk/platforms" | ||
) | ||
|
||
func TestBuildURLFromFormat(t *testing.T) { | ||
osName, err := platforms.DetermineOperatingSystem() | ||
if err != nil { | ||
t.Fatalf("Cannot get operating system name: %v", err) | ||
} | ||
|
||
version := "6.0.0" | ||
|
||
machineName, err := platforms.DetermineArchitecture(osName, version) | ||
if err != nil { | ||
t.Fatalf("Cannot get machine architecture name: %v", err) | ||
} | ||
|
||
suffix := platforms.DetermineExecutableFilenameSuffix() | ||
|
||
type test struct { | ||
format string | ||
want string | ||
wantErr error | ||
} | ||
|
||
tests := []test{ | ||
{format: "", want: ""}, | ||
{format: "no/placeholders", want: "no/placeholders"}, | ||
|
||
{format: "%", wantErr: errors.New("trailing %")}, | ||
{format: "%%", want: "%"}, | ||
{format: "%%%%", want: "%%"}, | ||
{format: "invalid/trailing/%", wantErr: errors.New("trailing %")}, | ||
{format: "escaped%%placeholder", want: "escaped%placeholder"}, | ||
|
||
{format: "foo-%e-bar", want: fmt.Sprintf("foo-%s-bar", suffix)}, | ||
{format: "foo-%m-bar", want: fmt.Sprintf("foo-%s-bar", machineName)}, | ||
{format: "foo-%o-bar", want: fmt.Sprintf("foo-%s-bar", osName)}, | ||
{format: "foo-%v-bar", want: fmt.Sprintf("foo-%s-bar", version)}, | ||
|
||
{format: "repeated %v %m %v", want: fmt.Sprintf("repeated %s %s %s", version, machineName, version)}, | ||
|
||
{format: "https://real.example.com/%e/%m/%o/%v#%%20trailing", want: fmt.Sprintf("https://real.example.com/%s/%s/%s/%s#%%20trailing", suffix, machineName, osName, version)}, | ||
} | ||
|
||
for _, tc := range tests { | ||
got, err := BuildURLFromFormat(tc.format, version) | ||
if fmt.Sprintf("%v", err) != fmt.Sprintf("%v", tc.wantErr) { | ||
if got != "" { | ||
t.Errorf("format '%s': got non-empty '%s' on error", tc.format, got) | ||
} | ||
t.Errorf("format '%s': got error %v, want error %v", tc.format, err, tc.wantErr) | ||
} else if got != tc.want { | ||
t.Errorf("format '%s': got %s, want %s", tc.format, got, tc.want) | ||
} | ||
} | ||
} |
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