diff --git a/cmd/trix/main_test.go b/cmd/trix/main_test.go index c99abf2..6841a84 100644 --- a/cmd/trix/main_test.go +++ b/cmd/trix/main_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "io" "os" "strings" @@ -32,6 +33,27 @@ func TestMain_Good(t *testing.T) { assert.Contains(t, buf.String(), "Usage:") } +func TestMain_Bad(t *testing.T) { + oldExit := exit + defer func() { exit = oldExit }() + var exitCode int + exit = func(code int) { + exitCode = code + } + rootCmd.RunE = func(cmd *cobra.Command, args []string) error { + return errors.New("test error") + } + // The rootCmd needs to be reset so that the test can be run again + defer func() { rootCmd = &cobra.Command{ + Use: "trix", + Short: "A tool for encoding and decoding .trix files", + Long: `trix is a command-line tool for working with the .trix file format, which is used for storing encrypted data.`, + } + }() + main() + assert.Equal(t, 1, exitCode) +} + func TestHandleSigil_Good(t *testing.T) { // Create a dummy command cmd := &cobra.Command{} diff --git a/pkg/crypt/std/pgp/pgp_test.go b/pkg/crypt/std/pgp/pgp_test.go index 176fa2f..f2cf679 100644 --- a/pkg/crypt/std/pgp/pgp_test.go +++ b/pkg/crypt/std/pgp/pgp_test.go @@ -64,6 +64,9 @@ func TestService_Decrypt_Bad(t *testing.T) { require.NoError(t, err) _, err = s.Decrypt(priv2, encrypted) assert.Error(t, err) + + _, err = s.Decrypt(priv2, []byte("bad encrypted data")) + assert.Error(t, err) } func TestService_Sign_Good(t *testing.T) {