-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2225 Note: this test won't fail when Goreleaser creates binaries that break Ledger support. However, this may catch when we bump a dependency that breaks Ledger support.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ledger | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLedgerSupport(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping ledger support test in short mode.") | ||
} | ||
|
||
type testCase struct { | ||
name string | ||
ledger bool | ||
want string | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
name: "ledger support enabled", | ||
ledger: true, | ||
want: "Error: failed to generate ledger key: failed to retrieve device: ledger nano S: LedgerHID device (idx 0) not found. Ledger LOCKED OR Other Program/Web Browser may have control of device.\n", | ||
}, | ||
{ | ||
name: "ledger support disabled", | ||
ledger: false, | ||
want: "Error: failed to generate ledger key: failed to retrieve device: ledger nano S: support for ledger devices is not available in this executable\n", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
var cmd *exec.Cmd | ||
if tc.ledger { | ||
// Generate the binary with Ledger support | ||
cmd = exec.Command("go", "build", "-tags", "ledger", "-o", "celestia-appd", "../../cmd/celestia-appd") | ||
} else { | ||
// Generate the binary without Ledger support | ||
cmd = exec.Command("go", "build", "-o", "celestia-appd", "../../cmd/celestia-appd") | ||
} | ||
err := cmd.Run() | ||
require.NoError(t, err) | ||
|
||
// Clean up the binary | ||
defer os.Remove("celestia-appd") | ||
|
||
// Run the binary | ||
cmd = exec.Command("./celestia-appd", "keys", "add", "test-key-name", "--ledger") | ||
var out bytes.Buffer | ||
cmd.Stderr = &out | ||
err = cmd.Run() | ||
require.Error(t, err) | ||
assert.Equal(t, tc.want, out.String()) | ||
}) | ||
} | ||
} |