-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Raphexion/nijo/refactor-to-use-backend-abs…
…traction Nijo/refactor to use backend abstraction
- Loading branch information
Showing
16 changed files
with
346 additions
and
274 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package backend | ||
|
||
import ( | ||
"nina/noko" | ||
) | ||
|
||
// Backend | ||
type Backend interface { | ||
Init() error | ||
|
||
// Timers | ||
GetTimers() ([]noko.Timer, error) | ||
GetTimersWithState(state string) ([]noko.Timer, error) | ||
GetRunningTimer() (*noko.Timer, error) | ||
PauseTimer(timer *noko.Timer) error | ||
StartTimer(timer *noko.Timer) error | ||
LogTimer(timer *noko.Timer) error | ||
CreateTimer(project *noko.Project) (*noko.Timer, error) | ||
DeleteTimer(timer *noko.Timer) error | ||
SetDescription(timer *noko.Timer, description string) error | ||
SetDescriptionOnRunningTimer(description string) error | ||
AddOrSubTimer(timer *noko.Timer, minutes int) error | ||
PauseRunningTimer() error | ||
GetProjects() ([]noko.Project, error) | ||
GetSomeProjects(withTimer bool) ([]noko.Project, error) | ||
|
||
// Entries | ||
GetEntries() ([]noko.Entry, error) | ||
|
||
// Output | ||
Write(p []byte) (n int, err error) | ||
} |
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,85 @@ | ||
package backend | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"nina/noko" | ||
) | ||
|
||
var ErrNotImplemented = errors.New("not implemented") | ||
|
||
type MockBackend struct { | ||
Projects []noko.Project | ||
Timers []noko.Timer | ||
Entries []noko.Entry | ||
Output *bytes.Buffer | ||
} | ||
|
||
func (m *MockBackend) Init() error { | ||
b := make([]byte, 0, 4096) | ||
m.Output = bytes.NewBuffer(b) | ||
return nil | ||
} | ||
|
||
func (m *MockBackend) Write(p []byte) (n int, err error) { | ||
return m.Output.Write(p) | ||
} | ||
|
||
func (m *MockBackend) GetTimers() ([]noko.Timer, error) { | ||
return m.Timers, nil | ||
} | ||
|
||
func (m *MockBackend) GetTimersWithState(state string) ([]noko.Timer, error) { | ||
return nil, ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) GetRunningTimer() (*noko.Timer, error) { | ||
return nil, ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) PauseTimer(timer *noko.Timer) error { | ||
return ErrNotImplemented | ||
} | ||
func (m *MockBackend) StartTimer(timer *noko.Timer) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) LogTimer(timer *noko.Timer) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) CreateTimer(project *noko.Project) (*noko.Timer, error) { | ||
return nil, ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) DeleteTimer(timer *noko.Timer) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) SetDescription(timer *noko.Timer, description string) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) SetDescriptionOnRunningTimer(description string) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) AddOrSubTimer(timer *noko.Timer, minutes int) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) PauseRunningTimer() error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) GetProjects() ([]noko.Project, error) { | ||
return m.Projects, nil | ||
} | ||
|
||
func (m *MockBackend) GetSomeProjects(withTimer bool) ([]noko.Project, error) { | ||
return nil, ErrNotImplemented | ||
} | ||
|
||
func (m *MockBackend) GetEntries() ([]noko.Entry, error) { | ||
return m.Entries, nil | ||
} |
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
Oops, something went wrong.