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

     1  package scenario
     2  
     3  import (
     4  	"github.com/filecoin-project/bacalhau/pkg/model"
     5  	"github.com/filecoin-project/bacalhau/testdata/wasm/cat"
     6  	"github.com/filecoin-project/bacalhau/testdata/wasm/csv"
     7  	"github.com/filecoin-project/bacalhau/testdata/wasm/env"
     8  	"github.com/filecoin-project/bacalhau/testdata/wasm/noop"
     9  )
    10  
    11  const helloWorld = "hello world"
    12  const simpleMountPath = "/data/file.txt"
    13  const simpleOutputPath = "/output_data/output_file.txt"
    14  const stdoutString = model.DownloadFilenameStdout
    15  const catProgram = "cat " + simpleMountPath + " > " + simpleOutputPath
    16  
    17  var CatFileToStdout = Scenario{
    18  	Inputs: StoredText(
    19  		helloWorld,
    20  		simpleMountPath,
    21  	),
    22  	ResultsChecker: ManyChecks(
    23  		FileEquals(model.DownloadFilenameStderr, ""),
    24  		FileEquals(model.DownloadFilenameStdout, helloWorld),
    25  	),
    26  	Spec: model.Spec{
    27  		Engine: model.EngineWasm,
    28  		Wasm: model.JobSpecWasm{
    29  			EntryPoint:  "_start",
    30  			EntryModule: InlineData(cat.Program()),
    31  			Parameters:  []string{simpleMountPath},
    32  		},
    33  	},
    34  }
    35  
    36  var CatFileToVolume = Scenario{
    37  	Inputs: StoredText(
    38  		catProgram,
    39  		simpleMountPath,
    40  	),
    41  	ResultsChecker: FileEquals(
    42  		"test/output_file.txt",
    43  		catProgram,
    44  	),
    45  	Outputs: []model.StorageSpec{
    46  		{
    47  			Name: "test",
    48  			Path: "/output_data",
    49  		},
    50  	},
    51  	Spec: model.Spec{
    52  		Engine: model.EngineDocker,
    53  		Docker: model.JobSpecDocker{
    54  			Image: "ubuntu:latest",
    55  			Entrypoint: []string{
    56  				"bash",
    57  				simpleMountPath,
    58  			},
    59  		},
    60  	},
    61  }
    62  
    63  var GrepFile = Scenario{
    64  	Inputs: StoredFile(
    65  		"../../../testdata/grep_file.txt",
    66  		simpleMountPath,
    67  	),
    68  	ResultsChecker: FileContains(
    69  		stdoutString,
    70  		"kiwi is delicious",
    71  		2,
    72  	),
    73  	Spec: model.Spec{
    74  		Engine: model.EngineDocker,
    75  		Docker: model.JobSpecDocker{
    76  			Image: "ubuntu:latest",
    77  			Entrypoint: []string{
    78  				"grep",
    79  				"kiwi",
    80  				simpleMountPath,
    81  			},
    82  		},
    83  	},
    84  }
    85  
    86  var SedFile = Scenario{
    87  	Inputs: StoredFile(
    88  		"../../../testdata/sed_file.txt",
    89  		simpleMountPath,
    90  	),
    91  	ResultsChecker: FileContains(
    92  		stdoutString,
    93  		"LISBON",
    94  		5, //nolint:gomnd // magic number ok for testing
    95  	),
    96  	Spec: model.Spec{
    97  		Engine: model.EngineDocker,
    98  		Docker: model.JobSpecDocker{
    99  			Image: "ubuntu:latest",
   100  			Entrypoint: []string{
   101  				"sed",
   102  				"-n",
   103  				"/38.7[2-4]..,-9.1[3-7]../p",
   104  				simpleMountPath,
   105  			},
   106  		},
   107  	},
   108  }
   109  
   110  var AwkFile = Scenario{
   111  	Inputs: StoredFile(
   112  		"../../../testdata/awk_file.txt",
   113  		simpleMountPath,
   114  	),
   115  	ResultsChecker: FileContains(
   116  		stdoutString,
   117  		"LISBON",
   118  		501, //nolint:gomnd // magic number appropriate for test
   119  	),
   120  	Spec: model.Spec{
   121  		Engine: model.EngineDocker,
   122  		Docker: model.JobSpecDocker{
   123  			Image: "ubuntu:latest",
   124  			Entrypoint: []string{
   125  				"awk",
   126  				"-F,",
   127  				"{x=38.7077507-$3; y=-9.1365919-$4; if(x^2+y^2<0.3^2) print}",
   128  				simpleMountPath,
   129  			},
   130  		},
   131  	},
   132  }
   133  
   134  var WasmHelloWorld = Scenario{
   135  	ResultsChecker: FileEquals(
   136  		stdoutString,
   137  		"Hello, world!\n",
   138  	),
   139  	Spec: model.Spec{
   140  		Engine: model.EngineWasm,
   141  		Wasm: model.JobSpecWasm{
   142  			EntryPoint:  "_start",
   143  			EntryModule: InlineData(noop.Program()),
   144  			Parameters:  []string{},
   145  		},
   146  	},
   147  }
   148  
   149  var WasmEnvVars = Scenario{
   150  	ResultsChecker: FileContains(
   151  		"stdout",
   152  		"AWESOME=definitely\nTEST=yes\n",
   153  		3, //nolint:gomnd // magic number appropriate for test
   154  	),
   155  	Spec: model.Spec{
   156  		Engine: model.EngineWasm,
   157  		Wasm: model.JobSpecWasm{
   158  			EntryPoint:  "_start",
   159  			EntryModule: InlineData(env.Program()),
   160  			EnvironmentVariables: map[string]string{
   161  				"TEST":    "yes",
   162  				"AWESOME": "definitely",
   163  			},
   164  		},
   165  	},
   166  }
   167  
   168  var WasmCsvTransform = Scenario{
   169  	Inputs: StoredFile(
   170  		"../../../testdata/wasm/csv/inputs",
   171  		"/inputs",
   172  	),
   173  	ResultsChecker: FileContains(
   174  		"outputs/parents-children.csv",
   175  		"http://www.wikidata.org/entity/Q14949904,Tugela,http://www.wikidata.org/entity/Q1001792,Makybe Diva",
   176  		269, //nolint:gomnd // magic number appropriate for test
   177  	),
   178  	Spec: model.Spec{
   179  		Engine: model.EngineWasm,
   180  		Wasm: model.JobSpecWasm{
   181  			EntryPoint:  "_start",
   182  			EntryModule: InlineData(csv.Program()),
   183  			Parameters: []string{
   184  				"inputs/horses.csv",
   185  				"outputs/parents-children.csv",
   186  			},
   187  		},
   188  	},
   189  	Outputs: []model.StorageSpec{
   190  		{
   191  			Name: "outputs",
   192  			Path: "/outputs",
   193  		},
   194  	},
   195  }
   196  
   197  func GetAllScenarios() map[string]Scenario {
   198  	return map[string]Scenario{
   199  		"cat_file_to_stdout": CatFileToStdout,
   200  		"cat_file_to_volume": CatFileToVolume,
   201  		"grep_file":          GrepFile,
   202  		"sed_file":           SedFile,
   203  		"awk_file":           AwkFile,
   204  		"wasm_hello_world":   WasmHelloWorld,
   205  		"wasm_env_vars":      WasmEnvVars,
   206  		"wasm_csv_transform": WasmCsvTransform,
   207  	}
   208  }