github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/devstack/errorlogs_test.go (about)

     1  //go:build integration
     2  
     3  package devstack
     4  
     5  import (
     6  	"context"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/filecoin-project/bacalhau/pkg/docker"
    11  	"github.com/filecoin-project/bacalhau/pkg/executor"
    12  	"github.com/filecoin-project/bacalhau/pkg/executor/noop"
    13  	"github.com/filecoin-project/bacalhau/pkg/job"
    14  	_ "github.com/filecoin-project/bacalhau/pkg/logger"
    15  	"github.com/filecoin-project/bacalhau/pkg/model"
    16  	"github.com/filecoin-project/bacalhau/pkg/test/scenario"
    17  	"github.com/stretchr/testify/suite"
    18  )
    19  
    20  type DevstackErrorLogsSuite struct {
    21  	scenario.ScenarioRunner
    22  }
    23  
    24  func TestDevstackErrorLogsSuite(t *testing.T) {
    25  	suite.Run(t, new(DevstackErrorLogsSuite))
    26  }
    27  
    28  var executorTestCases = []model.Spec{
    29  	{
    30  		Engine:    model.EngineNoop,
    31  		Publisher: model.PublisherIpfs,
    32  	},
    33  	{
    34  		Engine:    model.EngineDocker,
    35  		Publisher: model.PublisherIpfs,
    36  		Docker: model.JobSpecDocker{
    37  			Image:      "ubuntu",
    38  			Entrypoint: []string{"bash", "-c", "echo -n 'apples' >&1; echo -n 'oranges' >&2; exit 19;"},
    39  		},
    40  	},
    41  }
    42  
    43  var errorLogsTestCase = scenario.Scenario{
    44  	Stack: &scenario.StackConfig{
    45  		ExecutorConfig: noop.ExecutorConfig{
    46  			ExternalHooks: noop.ExecutorConfigExternalHooks{
    47  				JobHandler: func(ctx context.Context, shard model.JobShard, resultsDir string) (*model.RunCommandResult, error) {
    48  					return executor.WriteJobResults(resultsDir, strings.NewReader("apples"), strings.NewReader("oranges"), 19, nil)
    49  				},
    50  			},
    51  		},
    52  	},
    53  	ResultsChecker: scenario.ManyChecks(
    54  		scenario.FileEquals(model.DownloadFilenameStdout, "apples"),
    55  		scenario.FileEquals(model.DownloadFilenameStderr, "oranges"),
    56  	),
    57  	JobCheckers: []job.CheckStatesFunction{
    58  		job.WaitForSuccessfulCompletion(),
    59  	},
    60  }
    61  
    62  func (suite *DevstackErrorLogsSuite) TestCanGetResultsFromErroredJob() {
    63  	for _, testCase := range executorTestCases {
    64  		suite.Run(testCase.Engine.String(), func() {
    65  			docker.MaybeNeedDocker(suite.T(), testCase.Engine == model.EngineDocker)
    66  
    67  			scenario := errorLogsTestCase
    68  			scenario.Spec = testCase
    69  			suite.RunScenario(scenario)
    70  		})
    71  	}
    72  }