-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMPROVEMENT-24: Move mocks into a separate folder
- Loading branch information
1 parent
790c038
commit 70b616b
Showing
5 changed files
with
84 additions
and
3 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,15 @@ | ||
package mock | ||
|
||
type MockLogger struct{} | ||
|
||
func (l *MockLogger) Debug(format string, args ...any) { | ||
} | ||
|
||
func (l *MockLogger) Info(format string, args ...any) { | ||
} | ||
|
||
func (l *MockLogger) Error(format string, args ...any) { | ||
} | ||
|
||
func (l *MockLogger) Close() { | ||
} |
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,65 @@ | ||
package mock | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/grafviktor/goto/internal/model" | ||
) | ||
|
||
// =============================================== Storage | ||
|
||
func NewMockStorage(shouldFail bool) *mockStorage { | ||
hosts := []model.Host{ | ||
model.NewHost(0, "Mock Host", "", "localhost", "root", "id_rsa", "2222"), | ||
model.NewHost(0, "Mock Host", "", "localhost", "root", "id_rsa", "2222"), | ||
model.NewHost(0, "Mock Host", "", "localhost", "root", "id_rsa", "2222"), | ||
} | ||
|
||
return &mockStorage{ | ||
shouldFail: shouldFail, | ||
Hosts: hosts, | ||
} | ||
} | ||
|
||
type mockStorage struct { | ||
shouldFail bool | ||
Hosts []model.Host | ||
} | ||
|
||
// Delete implements storage.HostStorage. | ||
func (ms *mockStorage) Delete(id int) error { | ||
if ms.shouldFail { | ||
return errors.New("mock error") | ||
} | ||
|
||
ms.Hosts = append(ms.Hosts[:id], ms.Hosts[id+1:]...) | ||
|
||
return nil | ||
} | ||
|
||
// Get implements storage.HostStorage. | ||
func (ms *mockStorage) Get(hostID int) (model.Host, error) { | ||
if ms.shouldFail { | ||
return model.Host{}, errors.New("mock error") | ||
} | ||
|
||
return model.Host{}, nil | ||
} | ||
|
||
// GetAll implements storage.HostStorage. | ||
func (ms *mockStorage) GetAll() ([]model.Host, error) { | ||
if ms.shouldFail { | ||
return ms.Hosts, errors.New("mock error") | ||
} | ||
|
||
return ms.Hosts, nil | ||
} | ||
|
||
// Save implements storage.HostStorage. | ||
func (ms *mockStorage) Save(m model.Host) (model.Host, error) { | ||
if ms.shouldFail { | ||
return m, errors.New("mock error") | ||
} | ||
|
||
return m, nil | ||
} |