github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/test/cli/dir_root_scan_regression_test.go (about)

     1  package cli
     2  
     3  import (
     4  	"os/exec"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestDirectoryScanCompletesWithinTimeout(t *testing.T) {
    10  	image := "alpine:latest"
    11  
    12  	// we want to pull the image ahead of the test as to not affect the timeout value
    13  	pullDockerImage(t, image)
    14  
    15  	var cmd *exec.Cmd
    16  	var stdout, stderr string
    17  	done := make(chan struct{})
    18  	go func() {
    19  		defer close(done)
    20  		cmd, stdout, stderr = runBuildxInDocker(t, nil, image, "dir:/", "-vv")
    21  	}()
    22  
    23  	select {
    24  	case <-done:
    25  		break
    26  	case <-time.After(10 * time.Second):
    27  		t.Fatalf("directory scan is taking too long")
    28  	}
    29  
    30  	assertions := []traitAssertion{
    31  		assertTableReport,
    32  		assertSuccessfulReturnCode,
    33  	}
    34  
    35  	for _, traitFn := range assertions {
    36  		traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
    37  	}
    38  
    39  	logOutputOnFailure(t, cmd, stdout, stderr)
    40  
    41  }