-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): commands check version currency before running
Now that we have departed from packaging the CLI tools as part of pact-go, we needed a mechanism to ensure the tools matched the library. The only sensible time for this is at runtime, prior to executing the tests.
- Loading branch information
Showing
11 changed files
with
125 additions
and
34 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,45 +1,89 @@ | ||
package install | ||
|
||
import ( | ||
"fmt" | ||
"errors" | ||
"testing" | ||
) | ||
|
||
// TODO: mock out the file system | ||
type testCommander struct { | ||
// Version to return | ||
version string | ||
|
||
// Error to return | ||
err error | ||
} | ||
|
||
// set version range to be the same for all binaries | ||
func initVersionRange() { | ||
versionMap = map[string]string{ | ||
"pact-mock-service": ">= 1.0.0, < 2.0.0", | ||
"pact-provider-verifier": ">= 1.0.0, < 2.0.0", | ||
"pact-broker": ">= 1.0.0, < 2.0.0", | ||
} | ||
} | ||
|
||
func (c testCommander) Output(command string, args ...string) ([]byte, error) { | ||
return []byte(c.version), c.err | ||
} | ||
|
||
func getInstaller(version string, err error) *Installer { | ||
initVersionRange() | ||
return &Installer{testCommander{version, err}} | ||
} | ||
|
||
func TestInstaller_CheckVersion(t *testing.T) { | ||
i := Installer{} | ||
err := i.CheckVersion("pact-mock-service", "2.7.3") | ||
i := getInstaller("1.5.0", nil) | ||
err := i.CheckVersion("pact-mock-service", "1.5.0") | ||
|
||
if err != nil { | ||
t.Fatal("error:", err) | ||
} | ||
} | ||
|
||
func TestInstaller_CheckVersionFail(t *testing.T) { | ||
i := Installer{} | ||
err := i.CheckVersion("pact-mock-service", "3.7.3") | ||
i := getInstaller("2.0.0", nil) | ||
err := i.CheckVersion("pact-mock-service", "2.0.0") | ||
|
||
if err == nil { | ||
t.Fatal("want error, got none") | ||
} | ||
} | ||
|
||
func TestInstaller_getVersionForBinary(t *testing.T) { | ||
i := Installer{} | ||
version := "1.5.0" | ||
i := getInstaller(version, nil) | ||
v, err := i.GetVersionForBinary("pact-mock-service") | ||
|
||
if err != nil { | ||
t.Fatal("error:", err) | ||
} | ||
if v != version { | ||
t.Fatal("Want", version, "got", v) | ||
} | ||
} | ||
|
||
func TestInstaller_getVersionForBinaryError(t *testing.T) { | ||
i := getInstaller("", errors.New("test error")) | ||
_, err := i.GetVersionForBinary("pact-mock-service") | ||
|
||
fmt.Println("version: ", v) | ||
if err == nil { | ||
t.Fatal("Want error, got nil") | ||
} | ||
} | ||
|
||
func TestInstaller_CheckInstallation(t *testing.T) { | ||
i := Installer{} | ||
i := getInstaller("1.0.0", nil) | ||
err := i.CheckInstallation() | ||
|
||
if err != nil { | ||
t.Fatal("error:", err) | ||
} | ||
} | ||
func TestInstaller_CheckInstallationError(t *testing.T) { | ||
i := getInstaller("2.0.0", nil) | ||
err := i.CheckInstallation() | ||
|
||
if err == nil { | ||
t.Fatal("Want error, got nil") | ||
} | ||
} |