Fix tests: add timeout to long-running failures, update SPDX license list (#989)

This commit is contained in:
Jonas Xavier
2022-05-09 11:48:44 -04:00
committed by GitHub
parent d2d532f4a8
commit 42f8601919
3 changed files with 82 additions and 61 deletions
+21 -7
View File
@@ -2,6 +2,7 @@ package cli
import (
"bytes"
"context"
"fmt"
"math"
"os"
@@ -13,7 +14,9 @@ import (
"testing"
"time"
"github.com/anchore/stereoscope"
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/stretchr/testify/require"
)
func setupPKI(t *testing.T, pw string) func() {
@@ -51,8 +54,20 @@ func setupPKI(t *testing.T, pw string) func() {
func getFixtureImage(t testing.TB, fixtureImageName string) string {
t.Logf("obtaining fixture image for %s", fixtureImageName)
imagetest.GetFixtureImage(t, "docker-archive", fixtureImageName)
return imagetest.GetFixtureImageTarPath(t, fixtureImageName)
request := imagetest.PrepareFixtureImage(t, "docker-archive", fixtureImageName)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
i, err := stereoscope.GetImage(ctx, request)
t.Logf("got image %s: %s", fixtureImageName, i.Metadata.ID)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, i.Cleanup())
})
path := imagetest.GetFixtureImageTarPath(t, fixtureImageName)
t.Logf("returning %s: %s", fixtureImageName, path)
return path
}
func pullDockerImage(t testing.TB, image string) {
@@ -85,7 +100,10 @@ func runSyftInDocker(t testing.TB, env map[string]string, image string, args ...
}
func runSyft(t testing.TB, env map[string]string, args ...string) (*exec.Cmd, string, string) {
cmd := getSyftCommand(t, args...)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
cmd := exec.CommandContext(ctx, getSyftBinaryLocation(t), args...)
if env == nil {
env = make(map[string]string)
}
@@ -135,10 +153,6 @@ func envMapToSlice(env map[string]string) (envList []string) {
return
}
func getSyftCommand(t testing.TB, args ...string) *exec.Cmd {
return exec.Command(getSyftBinaryLocation(t), args...)
}
func getSyftBinaryLocation(t testing.TB) string {
if os.Getenv("SYFT_BINARY_LOCATION") != "" {
// SYFT_BINARY_LOCATION is the absolute path to the snapshot binary