Exemple #1
0
func TestMockSave(t *testing.T) {
	b := backends.NewMockBackend()

	if err := b.Save(mockTestData); err != nil {
		t.Errorf("Load failed with %s", err)
	}
}
Exemple #2
0
func TestMockBackup(t *testing.T) {
	b := backends.NewMockBackend()

	if err := b.Backup(); err != nil {
		t.Errorf("Backup failed with %s", err)
	}
}
Exemple #3
0
func TestLoad(t *testing.T) {
	backendConfig := backends.Config{
		Type: backends.ConfigTypeMock,
	}
	backendClient := backends.NewMockBackend()
	for i, cryptoConfig := range safeCryptoConfigs {
		cryptoClient, err := crypto.New(&cryptoConfig)
		if err != nil {
			t.Fatalf("#%d: failed to create crypto client: %s", i, err.Error())
		}
		conf := &config.Config{
			Encryption: cryptoConfig,
			Storage:    backendConfig,
		}
		for j, data := range safeData {
			backendClient.Data = []byte(data)
			s, err := safe.Load([]byte(password), backendClient, cryptoClient, conf)
			if err != nil {
				t.Fatalf("#%d.#%d: failed to load safe: %s", i, j, err.Error())
			}
			if _, err := s.Get("foo"); err != nil {
				t.Fatalf("#%d.#%d: failed to get 'foo' safe account: %s", i, j, err.Error())
			}
		}
	}
}
Exemple #4
0
func TestMockLoad(t *testing.T) {
	b := backends.NewMockBackend()
	b.Data = mockTestData

	data, err := b.Load()
	if err != nil {
		t.Errorf("Load failed with %s", err)
	}
	if !reflect.DeepEqual(data, mockTestData) {
		t.Errorf("Load data returned unexpected data. Expected: '%s', Actual: '%s'", mockTestData, data)
	}
}
Exemple #5
0
func TestNewMockBackend(t *testing.T) {
	if b := backends.NewMockBackend(); b == nil {
		t.Errorf("Expected new mockBackend, got nil")
	}
}