-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from sirlatrom/feature/no-semantic-downgrades
Prevent semantic downgrades in `bin update`
- Loading branch information
Showing
4 changed files
with
94 additions
and
118 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,73 @@ | ||
package cmd | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/marcosnils/bin/pkg/config" | ||
"github.com/marcosnils/bin/pkg/providers" | ||
) | ||
|
||
type mockProvider struct { | ||
providers.Provider | ||
latestVersion string | ||
latestVersionURL string | ||
err error | ||
} | ||
|
||
func (m mockProvider) GetLatestVersion() (string, string, error) { | ||
return m.latestVersion, m.latestVersionURL, m.err | ||
} | ||
|
||
func (m mockProvider) GetID() string { | ||
return "github" | ||
} | ||
|
||
func TestGetLatestVersion(t *testing.T) { | ||
type mockValues struct { | ||
latestVersion string | ||
latestVersionURL string | ||
err error | ||
} | ||
cases := []struct { | ||
in *config.Binary | ||
m mockValues | ||
out *updateInfo | ||
}{ | ||
{ | ||
&config.Binary{ | ||
Path: "/home/user/bin/launchpad", | ||
Version: "1.1.0", | ||
URL: "https://github.com/Mirantis/launchpad/releases/download/1.1.0/launchpad-linux-x64", | ||
RemoteName: "launchpad-linux-x64", | ||
Provider: "github", | ||
}, | ||
mockValues{"1.1.1", "https://github.com/Mirantis/launchpad/releases/download/1.1.1/launchpad-linux-x64", nil}, | ||
&updateInfo{ | ||
version: "1.1.1", | ||
url: "https://github.com/Mirantis/launchpad/releases/download/1.1.1/launchpad-linux-x64", | ||
}, | ||
}, | ||
{ | ||
&config.Binary{ | ||
Path: "/home/user/bin/launchpad", | ||
Version: "1.2.0-rc.1", | ||
URL: "https://github.com/Mirantis/launchpad/releases/download/1.2.0-rc.1/launchpad-linux-x64", | ||
RemoteName: "launchpad-linux-x64", | ||
Provider: "github", | ||
}, | ||
mockValues{"1.1.1", "https://github.com/Mirantis/launchpad/releases/download/1.1.1/launchpad-linux-x64", nil}, | ||
nil, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
p := mockProvider{latestVersion: c.m.latestVersion, latestVersionURL: c.m.latestVersionURL, err: c.m.err} | ||
if v, err := getLatestVersion(c.in, p); err != nil { | ||
t.Fatalf("Error during getLatestVersion(%#v, %#v): %v", c.in, p, err) | ||
} else if !reflect.DeepEqual(v, c.out) { | ||
t.Fatalf("For case %#v: %#v does not match %#v", c.in, v, c.out) | ||
} | ||
} | ||
|
||
} |
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.