Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pahatz committed Oct 21, 2024
1 parent 503a1ec commit b601045
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/integration/tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (suite *TestSuite) TestInvalidUrl() {
"file2",
}

err := Download(os.Args)
err := Download(os.Args, "")
assert.Contains(
suite.T(),
err.Error(),
Expand Down
10 changes: 5 additions & 5 deletions htsget/htsget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ 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")
}

// test Htsget with mocked http request

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."
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}
6 changes: 3 additions & 3 deletions list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
38 changes: 19 additions & 19 deletions upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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())
Expand Down Expand Up @@ -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")), "\\\\", "\\")
Expand All @@ -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()))
Expand Down Expand Up @@ -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"))
Expand All @@ -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(`
Expand All @@ -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 {
Expand Down Expand Up @@ -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()))))
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down

0 comments on commit b601045

Please sign in to comment.