github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/devstack/combodriver_test.go (about) 1 //go:build integration 2 3 package devstack 4 5 import ( 6 "fmt" 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/filecoin-project/bacalhau/pkg/devstack" 12 "github.com/filecoin-project/bacalhau/pkg/job" 13 _ "github.com/filecoin-project/bacalhau/pkg/logger" 14 "github.com/filecoin-project/bacalhau/pkg/model" 15 "github.com/filecoin-project/bacalhau/pkg/test/scenario" 16 "github.com/stretchr/testify/require" 17 "github.com/stretchr/testify/suite" 18 ) 19 20 type ComboDriverSuite struct { 21 scenario.ScenarioRunner 22 } 23 24 // In order for 'go test' to run this suite, we need to create 25 // a normal test function and pass our suite to suite.Run 26 func TestComboDriverSuite(t *testing.T) { 27 suite.Run(t, new(ComboDriverSuite)) 28 } 29 30 const exampleText = "hello world" 31 32 var testcase = scenario.Scenario{ 33 ResultsChecker: scenario.FileEquals(model.DownloadFilenameStdout, exampleText), 34 Spec: model.Spec{ 35 Engine: model.EngineWasm, 36 Verifier: model.VerifierNoop, 37 Publisher: model.PublisherIpfs, 38 Wasm: model.JobSpecWasm{ 39 EntryPoint: scenario.CatFileToStdout.Spec.Wasm.EntryPoint, 40 EntryModule: scenario.CatFileToStdout.Spec.Wasm.EntryModule, 41 Parameters: []string{ 42 `/inputs/file.txt`, 43 }, 44 }, 45 }, 46 Outputs: []model.StorageSpec{ 47 { 48 Name: "outputs", 49 Path: "/outputs/", 50 }, 51 }, 52 JobCheckers: []job.CheckStatesFunction{ 53 job.WaitForSuccessfulCompletion(), 54 }, 55 } 56 57 // Test that the combo driver gives preference to the filecoin unsealed driver 58 // also that this does not affect normal jobs where the CID resides on the IPFS driver 59 func (suite *ComboDriverSuite) TestComboDriverSealed() { 60 testcase.Inputs = scenario.StoredText(exampleText, "/inputs/file.txt") 61 suite.RunScenario(testcase) 62 } 63 64 func (suite *ComboDriverSuite) TestComboDriverUnsealed() { 65 cid := "apples" 66 basePath := suite.T().TempDir() 67 err := os.MkdirAll(filepath.Join(basePath, cid), os.ModePerm) 68 require.NoError(suite.T(), err) 69 70 filePath := filepath.Join(basePath, cid, "file.txt") 71 err = os.WriteFile(filePath, []byte(fmt.Sprintf(exampleText)), 0644) 72 require.NoError(suite.T(), err) 73 74 testcase.Stack = &scenario.StackConfig{ 75 DevStackOptions: &devstack.DevStackOptions{ 76 NumberOfHybridNodes: 1, 77 PublicIPFSMode: false, 78 FilecoinUnsealedPath: fmt.Sprintf("%s/{{.CID}}", basePath), 79 }, 80 } 81 82 suite.RunScenario(testcase) 83 }