From 08458f4626c641bb92804240b78302471252a20d Mon Sep 17 00:00:00 2001 From: Joakim Bygdell Date: Mon, 18 Dec 2023 08:22:57 +0100 Subject: [PATCH] [decrypt_test] Fix windows test case --- decrypt/decrypt_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/decrypt/decrypt_test.go b/decrypt/decrypt_test.go index 94a15ad6..6e142c29 100644 --- a/decrypt/decrypt_test.go +++ b/decrypt/decrypt_test.go @@ -5,6 +5,7 @@ import ( "io" "os" "path/filepath" + "runtime" "testing" createKey "github.com/NBISweden/sda-cli/create_key" @@ -97,8 +98,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} @@ -131,7 +136,7 @@ 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())) + assert.NoError(suite.T(), os.Rename(suite.testFile.Name(), filepath.Join(suite.tempDir, "fuu"))) os.Setenv("C4GH_PASSWORD", "") os.Args = []string{"decrypt", "-key", fmt.Sprintf("%s.sec.pem", testKeyFile), fmt.Sprintf("%s.c4gh", suite.testFile.Name())}