-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from guggero/newline-trim-fix
Newline trim fix
- Loading branch information
Showing
11 changed files
with
268 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
testSeedWithNewline = []byte("seed phrase with newline\n") | ||
testPasswordWithNewline = []byte("p4ssw0rd\r\n\n\r\r\n") | ||
) | ||
|
||
// TestReadInput makes sure input files are always trimmed so we don't have any | ||
// newline characters left over. | ||
func TestReadInput(t *testing.T) { | ||
cmd := newInitWalletCommand() | ||
|
||
cmd.File.Seed = writeToTempFile(t, testSeedWithNewline) | ||
cmd.File.WalletPassword = writeToTempFile(t, testPasswordWithNewline) | ||
|
||
seed, seedPassphrase, walletPassword, err := cmd.readInput(true) | ||
require.NoError(t, err) | ||
require.Equal(t, "seed phrase with newline", seed) | ||
require.Equal(t, "", seedPassphrase) | ||
require.Equal(t, "p4ssw0rd", walletPassword) | ||
} | ||
|
||
func writeToTempFile(t *testing.T, data []byte) string { | ||
tempFileName, err := ioutil.TempFile("", "*.txt") | ||
require.NoError(t, err) | ||
|
||
err = ioutil.WriteFile(tempFileName.Name(), data, 0600) | ||
require.NoError(t, err) | ||
|
||
return tempFileName.Name() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.