Skip to content

Commit

Permalink
[decrypt_test] Fix windows test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Dec 18, 2023
1 parent 0f54827 commit ac731ce
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions decrypt/decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"testing"
"time"

createKey "github.com/NBISweden/sda-cli/create_key"
"github.com/NBISweden/sda-cli/encrypt"
Expand Down Expand Up @@ -97,8 +99,12 @@ func (suite *DecryptTests) Testdecrypt() {
assert.NoError(suite.T(), err)

// Test decrypting a non-existent file
msg := "no such file or directory"
if runtime.GOOS == "windows" {
msg = "open somekey: The system cannot find the file specified."
}
err = decryptFile(filepath.Join(suite.tempDir, "non-existent"), "output_file", *privateKey)
assert.ErrorContains(suite.T(), err, "no such file or directory")
assert.ErrorContains(suite.T(), err, msg)

// Test decryption with malformed key
fakeKey := [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Expand Down Expand Up @@ -131,7 +137,13 @@ func (suite *DecryptTests) TestDecrypt() {
encryptArgs := []string{"encrypt", "-key", fmt.Sprintf("%s.pub.pem", testKeyFile), suite.testFile.Name()}
assert.NoError(suite.T(), encrypt.Encrypt(encryptArgs), "encrypting file for testing failed")
assert.NoError(suite.T(), os.Chdir(cwd))
assert.NoError(suite.T(), os.Remove(suite.testFile.Name()))
if runtime.GOOS == "windows" {
for os.Remove(suite.testFile.Name()) != nil {
time.Sleep(1 * time.Second)
}
} else {
assert.NoError(suite.T(), os.Remove(suite.testFile.Name()))
}

os.Setenv("C4GH_PASSWORD", "")
os.Args = []string{"decrypt", "-key", fmt.Sprintf("%s.sec.pem", testKeyFile), fmt.Sprintf("%s.c4gh", suite.testFile.Name())}
Expand Down

0 comments on commit ac731ce

Please sign in to comment.