Skip to content

Commit

Permalink
Error output to systemKeyring.List and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBQu committed Dec 18, 2024
1 parent 4131a0a commit c16d843
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
12 changes: 9 additions & 3 deletions keyring/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

package keyring

import "github.com/zalando/go-keyring"
import (
"github.com/zalando/go-keyring"

// ErrNotFound is returned when a keyring item is not found.
var ErrNotFound = keyring.ErrNotFound
"github.com/sourcenetwork/defradb/errors"
)

var (
ErrNotFound = keyring.ErrNotFound // ErrNotFound is returned when a keyring item is not found.
ErrSystemKeyringListInvoked = errors.New("listing keys is not supported by OS keyring")
)
2 changes: 1 addition & 1 deletion keyring/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ func (s *systemKeyring) List() ([]string, error) {
// The OS keyring does not support listing keys
// This function is a stub for now because the Keyring interface requires it
// Currently, the 'defradb keyring list' command uses only fileKeyring
return nil, nil
return nil, ErrSystemKeyringListInvoked
}
28 changes: 28 additions & 0 deletions keyring/system_keyring_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package keyring

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSystemKeyringListThrowsError(t *testing.T) {
service := "test-service"
systemKeyring := OpenSystemKeyring(service)

keys, err := systemKeyring.List()

assert.Nil(t, keys, "keys should be nil when List is called")
assert.Error(t, err, "an error should be returned when List is called")
assert.Equal(t, ErrSystemKeyringListInvoked, err, "the error should be ErrSystemKeyringListInvoked")
}

0 comments on commit c16d843

Please sign in to comment.