-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mike
committed
Oct 3, 2024
1 parent
e91ff3e
commit 1529431
Showing
5 changed files
with
102 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package security_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/security" | ||
Check failure on line 6 in pkg/security/storage_test.go GitHub Actions / runner / golangci-lint
|
||
|
||
"github.com/99designs/keyring" | ||
"github.com/stretchr/testify/mock" | ||
Check failure on line 9 in pkg/security/storage_test.go GitHub Actions / runner / golangci-lint
|
||
) | ||
|
||
// MockKeyring to mock the keyring interface for unit testing | ||
type MockKeyring struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockKeyring) Set(item keyring.Item) error { | ||
args := m.Called(item) | ||
return args.Error(0) | ||
} | ||
|
||
func (m *MockKeyring) Get(key string) (keyring.Item, error) { | ||
args := m.Called(key) | ||
return args.Get(0).(keyring.Item), args.Error(1) | ||
} | ||
|
||
func TestSetKeyValue(t *testing.T) { | ||
mockKeyring := new(MockKeyring) | ||
storage := security.NewStorage("testService", mockKeyring) | ||
|
||
mockKeyring.On("Set", keyring.Item{Key: "testKey", Data: []byte("testValue")}).Return(nil) | ||
|
||
err := storage.SetKeyValue("testKey", "testValue") | ||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
|
||
mockKeyring.AssertExpectations(t) | ||
} | ||
|
||
func TestGetKeyValue(t *testing.T) { | ||
mockKeyring := new(MockKeyring) | ||
storage := security.NewStorage("testService", mockKeyring) | ||
|
||
mockKeyring.On("Get", "testKey").Return(keyring.Item{Key: "testKey", Data: []byte("testValue")}, nil) | ||
|
||
value, err := storage.GetKeyValue("testKey") | ||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
|
||
if value != "testValue" { | ||
t.Errorf("Expected value 'testValue', got %v", value) | ||
} | ||
|
||
mockKeyring.AssertExpectations(t) | ||
} |
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