diff --git a/.github/integration/tests/tests.sh b/.github/integration/tests/tests.sh index dc72340..e33596d 100755 --- a/.github/integration/tests/tests.sh +++ b/.github/integration/tests/tests.sh @@ -150,7 +150,7 @@ else fi # Download file by using the sda download service -./sda-cli download -config testing/s3cmd-download.conf -dataset-id https://doi.example/ty009.sfrrss/600.45asasga -url http://localhost:8080 -outdir test-download main/subfolder/dummy_data.c4gh +./sda-cli -config testing/s3cmd-download.conf download -dataset-id https://doi.example/ty009.sfrrss/600.45asasga -url http://localhost:8080 -outdir test-download main/subfolder/dummy_data.c4gh # Check if file exists in the path if [ ! -f "test-download/main/subfolder/dummy_data" ]; then @@ -168,7 +168,7 @@ fi rm -r test-download # Check listing files in a dataset -output=$(./sda-cli list -config testing/s3cmd-download.conf -dataset https://doi.example/ty009.sfrrss/600.45asasga -url http://localhost:8080) +output=$(./sda-cli -config testing/s3cmd-download.conf list -dataset https://doi.example/ty009.sfrrss/600.45asasga -url http://localhost:8080) expected="FileIDSizePathurn:neic:001-0011.0MB5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8_elixir-europe.org/main/subfolder/dummy_data.c4ghurn:neic:001-0021.0MB5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8_elixir-europe.org/main/subfolder2/dummy_data2.c4ghurn:neic:001-0031.0MB5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8_elixir-europe.org/main/subfolder2/random/dummy_data3.c4ghDatasetsize:3.1MB" if [[ "${output//[$' \t\n\r']/}" == "${expected//[$' \t\n\r']/}" ]]; then echo "Successfully listed files in dataset" diff --git a/download/download_test.go b/download/download_test.go index 348c1ca..5b1e478 100644 --- a/download/download_test.go +++ b/download/download_test.go @@ -76,7 +76,7 @@ func (suite *TestSuite) TestInvalidUrl() { "file2", } - err := Download(os.Args) + err := Download(os.Args, "") assert.Contains( suite.T(), err.Error(), diff --git a/htsget/htsget_test.go b/htsget/htsget_test.go index 25beed3..e8c60b6 100644 --- a/htsget/htsget_test.go +++ b/htsget/htsget_test.go @@ -22,7 +22,7 @@ func TestConfigTestSuite(t *testing.T) { func (suite *TestSuite) MissingArgument() { os.Args = []string{"htsget"} - err := Htsget(os.Args) + err := Htsget(os.Args, "") assert.EqualError(suite.T(), err, "missing required arguments, dataset, filename, host and key are required") } @@ -30,7 +30,7 @@ func (suite *TestSuite) MissingArgument() { func (suite *TestSuite) TestHtsgetMissingConfig() { os.Args = []string{"htsget", "-config", "nonexistent.conf", "-dataset", "DATASET0001", "-filename", "htsnexus_test_NA12878", "-host", "somehost", "-pubkey", "somekey"} - err := Htsget(os.Args) + err := Htsget(os.Args, "") msg := "no such file or directory" if runtime.GOOS == "windows" { msg = "open nonexistent.conf: The system cannot find the file specified." @@ -59,7 +59,7 @@ access_token = eyJ0eXAiOiJKV1QiLCJqa3UiOiJodHRwczovL29pZGM6ODA4MC9qd2siLCJhbGciO panic(err) } os.Args = []string{"htsget", "-config", tmpDir + "s3cmd_test.conf", "-dataset", "DATASET0001", "-filename", "htsnexus_test_NA12878", "-host", "somehost", "-pubkey", "somekey"} - err = Htsget(os.Args) + err = Htsget(os.Args, "") assert.ErrorContains(suite.T(), err, "failed to read public key") } @@ -91,7 +91,7 @@ KKj6NUcJGZ2/HeqkYbxm57ZaFLP5cIHsdK+0nQubFVs= panic(err) } os.Args = []string{"htsget", "-config", tmpDir + "s3cmd_test.conf", "-dataset", "DATASET0001", "-filename", "htsnexus_test_NA12878", "-host", "missingserver", "-pubkey", tmpDir + "c4gh.pub.pem"} - err = Htsget(os.Args) + err = Htsget(os.Args, "") assert.ErrorContains(suite.T(), err, "failed to do the request") } @@ -185,6 +185,6 @@ KKj6NUcJGZ2/HeqkYbxm57ZaFLP5cIHsdK+0nQubFVs= defer server.Close() os.Args = []string{"htsget", "-config", tmpDir + "s3cmd_test.conf", "-dataset", "DATASET0001", "-filename", "htsnexus_test_NA12878", "-host", server.URL, "-pubkey", tmpDir + "c4gh.pub.pem"} - err = Htsget(os.Args) + err = Htsget(os.Args, "") assert.ErrorContains(suite.T(), err, "error downloading the files") } diff --git a/list/list_test.go b/list/list_test.go index e17dcbf..d8a0600 100644 --- a/list/list_test.go +++ b/list/list_test.go @@ -39,7 +39,7 @@ func (suite *TestSuite) TestNoConfig() { os.Args = []string{"list", "-config", ""} - err := List(os.Args) + err := List(os.Args, "") assert.EqualError(suite.T(), err, "failed to load config file, reason: failed to read the configuration file") } @@ -127,7 +127,7 @@ func (suite *TestSuite) TestFunctionality() { // Upload a file os.Args = []string{"upload", "--force-unencrypted", "-config", configPath.Name(), "-r", dir} - err = upload.Upload(os.Args) + err = upload.Upload(os.Args, "") assert.NoError(suite.T(), err) // Check logs that file was uploaded @@ -142,7 +142,7 @@ func (suite *TestSuite) TestFunctionality() { os.Stdout = w os.Args = []string{"list", "-config", configPath.Name()} - err = List(os.Args) + err = List(os.Args, "") assert.NoError(suite.T(), err) w.Close() diff --git a/upload/upload_test.go b/upload/upload_test.go index f5b6f17..926739e 100644 --- a/upload/upload_test.go +++ b/upload/upload_test.go @@ -72,15 +72,15 @@ func (suite *TestSuite) TestSampleNoFiles() { // Test Upload function os.Args = []string{"upload", "-config", configPath.Name()} - assert.EqualError(suite.T(), Upload(os.Args), "no files to upload") + assert.EqualError(suite.T(), Upload(os.Args, ""), "no files to upload") // Test handling of mistakenly passing a filename as an upload folder os.Args = []string{"upload", "-config", configPath.Name(), "-targetDir", configPath.Name()} - assert.EqualError(suite.T(), Upload(os.Args), configPath.Name()+" is not a valid target directory") + assert.EqualError(suite.T(), Upload(os.Args, ""), configPath.Name()+" is not a valid target directory") // Test handling of mistakenly passing a flag as an upload folder os.Args = []string{"upload", "-config", configPath.Name(), "-targetDir", "-r"} - assert.EqualError(suite.T(), Upload(os.Args), "-r"+" is not a valid target directory") + assert.EqualError(suite.T(), Upload(os.Args, ""), "-r"+" is not a valid target directory") // Test passing flags at the end as well @@ -89,10 +89,10 @@ func (suite *TestSuite) TestSampleNoFiles() { msg = "CreateFile somefileOrfolder: The system cannot find the file specified." } os.Args = []string{"upload", "-config", configPath.Name(), "-r", "somefileOrfolder", "-targetDir", "somedir"} - assert.EqualError(suite.T(), Upload(os.Args), msg) + assert.EqualError(suite.T(), Upload(os.Args, ""), msg) os.Args = []string{"upload", "-config", configPath.Name(), "somefiles", "-targetDir"} - assert.EqualError(suite.T(), Upload(os.Args), "no files to upload") + assert.EqualError(suite.T(), Upload(os.Args, ""), "no files to upload") // Test uploadFiles function config, _ := helpers.LoadConfigFile(configPath.Name()) @@ -220,7 +220,7 @@ func (suite *TestSuite) TestFunctionality() { // Test recursive upload os.Args = []string{"upload", "--force-unencrypted", "-config", configPath.Name(), "-r", dir} - assert.NoError(suite.T(), Upload(os.Args)) + assert.NoError(suite.T(), Upload(os.Args, "")) // Check logs that file was uploaded logMsg := strings.ReplaceAll(fmt.Sprintf("%v", strings.TrimSuffix(str.String(), "\n")), "\\\\", "\\") @@ -243,7 +243,7 @@ func (suite *TestSuite) TestFunctionality() { // Test upload to a different folder targetPath := filepath.Join("a", "b", "c") os.Args = []string{"upload", "--force-unencrypted", "-config", configPath.Name(), testfile.Name(), "-targetDir", targetPath} - assert.NoError(suite.T(), Upload(os.Args)) + assert.NoError(suite.T(), Upload(os.Args, "")) // Check logs that file was uploaded logMsg = fmt.Sprintf("%v", strings.TrimSuffix(str.String(), "\n")) msg = fmt.Sprintf("file uploaded to %s/dummy/%s/%s", ts.URL, filepath.ToSlash(targetPath), filepath.Base(testfile.Name())) @@ -280,7 +280,7 @@ func (suite *TestSuite) TestFunctionality() { // Empty buffer logs str.Reset() newArgs := []string{"upload", "--force-unencrypted", "-config", configPath.Name(), "--encrypt-with-key", publicKey.Name(), testfile.Name(), "-targetDir", "someDir"} - assert.NoError(suite.T(), Upload(newArgs)) + assert.NoError(suite.T(), Upload(newArgs, "")) // Check logs that encrypted file was uploaded logMsg = fmt.Sprintf("%v", strings.TrimSuffix(str.String(), "\n")) @@ -302,17 +302,17 @@ func (suite *TestSuite) TestFunctionality() { // Check that trying to encrypt already encrypted files returns error and aborts newArgs = []string{"upload", "-config", configPath.Name(), "--encrypt-with-key", publicKey.Name(), dir, "-r"} - assert.EqualError(suite.T(), Upload(newArgs), "aborting") + assert.EqualError(suite.T(), Upload(newArgs, ""), "aborting") // Check handling of passing source files as pub key // (code checks first for errors related with file args) newArgs = []string{"upload", "-config", configPath.Name(), "--encrypt-with-key", testfile.Name()} - assert.EqualError(suite.T(), Upload(newArgs), "no files to upload") + assert.EqualError(suite.T(), Upload(newArgs, ""), "no files to upload") // If both a bad key and already encrypted file args are given, // file arg errors are captured first newArgs = []string{"upload", "-config", configPath.Name(), "--encrypt-with-key", "somekey", testfile.Name()} - assert.EqualError(suite.T(), Upload(newArgs), "aborting") + assert.EqualError(suite.T(), Upload(newArgs, ""), "aborting") // config file without an access_token var confFileNoToken = fmt.Sprintf(` @@ -338,24 +338,24 @@ func (suite *TestSuite) TestFunctionality() { // Check that an access token is supplied newArgs = []string{"upload", "-config", configPath.Name(), testfile.Name()} - assert.EqualError(suite.T(), Upload(newArgs), "no access token supplied") + assert.EqualError(suite.T(), Upload(newArgs, ""), "no access token supplied") os.Setenv("ACCESSTOKEN", "BadToken") // Supplying an accesstoken as a ENV overrules the one in the config file newArgs = []string{"upload", "-config", configPath.Name(), testfile.Name()} - assert.EqualError(suite.T(), Upload(newArgs), "could not parse token, reason: token contains an invalid number of segments") + assert.EqualError(suite.T(), Upload(newArgs, ""), "could not parse token, reason: token contains an invalid number of segments") suite.SetupTest() os.Setenv("ACCESSTOKEN", suite.accessToken) newArgs = []string{"upload", "-config", configPath.Name(), testfile.Name()} - assert.NoError(suite.T(), Upload(newArgs)) + assert.NoError(suite.T(), Upload(newArgs, "")) // Supplying an accesstoken as a parameter overrules the one in the config file newArgs = []string{"upload", "-accessToken", "BadToken", "-config", configPath.Name(), testfile.Name()} - assert.EqualError(suite.T(), Upload(newArgs), "could not parse token, reason: token contains an invalid number of segments") + assert.EqualError(suite.T(), Upload(newArgs, ""), "could not parse token, reason: token contains an invalid number of segments") newArgs = []string{"upload", "-accessToken", suite.accessToken, "-config", configPath.Name(), testfile.Name()} - assert.NoError(suite.T(), Upload(newArgs)) + assert.NoError(suite.T(), Upload(newArgs, "")) // Remove hash files created by Encrypt if err := os.Remove("checksum_encrypted.md5"); err != nil { @@ -453,7 +453,7 @@ func (suite *TestSuite) TestRecursiveToDifferentTarget() { // Test recursive upload to a different folder targetPath := filepath.Join("a", "b", "c") os.Args = []string{"upload", "--force-unencrypted", "-config", configPath.Name(), "-r", dir, "-targetDir", targetPath} - assert.NoError(suite.T(), Upload(os.Args)) + assert.NoError(suite.T(), Upload(os.Args, "")) // Check logs that file was uploaded logMsg := fmt.Sprintf("%v", strings.TrimSuffix(str.String(), "\n")) msg := fmt.Sprintf("file uploaded to %s/dummy/%s", ts.URL, filepath.ToSlash(filepath.Join(targetPath, filepath.Base(dir), filepath.Base(testfile.Name())))) @@ -538,7 +538,7 @@ func (suite *TestSuite) TestUploadInvalidCharacters() { badchar := string(badc) targetDir := "test" + badchar + "dir" os.Args = []string{"upload", "--force-unencrypted", "-config", configPath.Name(), "-targetDir", targetDir, "-r", testfile.Name()} - err = Upload(os.Args) + err = Upload(os.Args, "") assert.Error(suite.T(), err) assert.Equal(suite.T(), targetDir+" is not a valid target directory", err.Error()) } @@ -564,7 +564,7 @@ func (suite *TestSuite) TestUploadInvalidCharacters() { defer os.Remove(testfile.Name()) os.Args = []string{"upload", "--force-unencrypted", "-config", configPath.Name(), "-r", testfile.Name()} - err = Upload(os.Args) + err = Upload(os.Args, "") assert.Error(suite.T(), err) assert.Equal(suite.T(), fmt.Sprintf("filepath %v contains disallowed characters: %+v", testfilepath, badchar), err.Error()) }