Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
update tests to load a proper config file
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Lours <[email protected]>
  • Loading branch information
glours committed Oct 27, 2020
1 parent e40a1ce commit accc94e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions e2e/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func TestSnykAuthentication(t *testing.T) {
homeDir, cleanFunction := createSnykConfFile(t, "")
defer cleanFunction()

cmd, _, cleanup := dockerCli.createTestCmd()
cmd, configDir, cleanup := dockerCli.createTestCmd()
defer cleanup()
createScanConfigFile(t, configDir)

token := os.Getenv("E2E_TEST_AUTH_TOKEN")
assert.Assert(t, token != "", "E2E_TEST_AUTH_TOKEN needs to be filled")
Expand Down Expand Up @@ -67,8 +68,9 @@ func TestAuthenticationFlagFailsWithImage(t *testing.T) {
}

func TestAuthenticationChecksToken(t *testing.T) {
cmd, _, cleanup := dockerCli.createTestCmd()
cmd, configDir, cleanup := dockerCli.createTestCmd()
defer cleanup()
createScanConfigFile(t, configDir)

cmd.Command = dockerCli.Command("scan", "--accept-license", "--login", "--token", "invalid-token")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
Expand Down
1 change: 1 addition & 0 deletions e2e/optin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Version:`))
func TestRefuseOptinWithDisableFlag(t *testing.T) {
cmd, configDir, cleanup := dockerCli.createTestCmd()
defer cleanup()
createScanConfigFile(t, configDir)

// docker scan --version should exit immediately
cmd.Command = dockerCli.Command("scan", "--reject-license", "--version")
Expand Down
4 changes: 3 additions & 1 deletion e2e/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestScanFailsNoAuthentication(t *testing.T) {

cmd, configDir, cleanup := dockerCli.createTestCmd()
defer cleanup()
createScanConfigFile(t, configDir)

// write dockerCli config with authentication to a registry which isn't Hub
patchConfig(t, configDir, "com.example.registry", "invalid-user", "invalid-password")
Expand All @@ -66,8 +67,9 @@ func TestScanFailsWithCleanMessage(t *testing.T) {
_, cleanFunction := createSnykConfFile(t, "")
defer cleanFunction()

cmd, _, cleanup := dockerCli.createTestCmd()
cmd, configDir, cleanup := dockerCli.createTestCmd()
defer cleanup()
createScanConfigFile(t, configDir)

cmd.Command = dockerCli.Command("scan", "--accept-license", "example:image")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
Expand Down
12 changes: 8 additions & 4 deletions e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ Provider: %s
}

func TestVersionWithoutSnykOrConfig(t *testing.T) {
cmd, _, cleanup := dockerCli.createTestCmd()
cmd, configDir, cleanup := dockerCli.createTestCmd()
defer cleanup()

// docker scan --version should fail with a clean error
cmd.Command = dockerCli.Command("scan", "--accept-license", "--version")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
output := icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: "could not find Snyk binary",
})
}).Combined()
expected := fmt.Sprintf(
`failed to read docker scan configuration file. Please restart Docker Desktop: open %s/scan/config.json: no such file or directory
`,
configDir)
assert.Equal(t, output, expected)
}

func getProviderVersion(env string) string {
Expand Down

0 comments on commit accc94e

Please sign in to comment.