-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test DataManager + fix errors (#88)
* feat: test DataManager + fix errors * chore: add test on not empty tallies
- Loading branch information
1 parent
696c541
commit 835d287
Showing
12 changed files
with
180 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package data | ||
|
||
import ( | ||
fetchersPkg "main/pkg/fetchers" | ||
"main/pkg/logger" | ||
"main/pkg/types" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDataManagerNew(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
dataManager := NewManager(log, types.Chains{ | ||
{Name: "chain"}, | ||
}) | ||
|
||
assert.NotNil(t, dataManager) | ||
} | ||
|
||
func TestDataManagerGetTallyWithError(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
dataManager := &Manager{ | ||
Logger: *log, | ||
Chains: types.Chains{{Name: "chain"}}, | ||
Fetchers: []fetchersPkg.Fetcher{&fetchersPkg.TestFetcher{WithTallyError: true}}, | ||
} | ||
|
||
tallies, err := dataManager.GetTallies() | ||
require.Error(t, err) | ||
assert.Empty(t, tallies) | ||
} | ||
|
||
func TestDataManagerGetTallyEmpty(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
dataManager := &Manager{ | ||
Logger: *log, | ||
Chains: types.Chains{{Name: "chain"}}, | ||
Fetchers: []fetchersPkg.Fetcher{&fetchersPkg.TestFetcher{}}, | ||
} | ||
|
||
tallies, err := dataManager.GetTallies() | ||
require.NoError(t, err) | ||
assert.Empty(t, tallies) | ||
} | ||
|
||
func TestDataManagerGetTallyOk(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
dataManager := &Manager{ | ||
Logger: *log, | ||
Chains: types.Chains{{Name: "chain"}}, | ||
Fetchers: []fetchersPkg.Fetcher{&fetchersPkg.TestFetcher{WithTallyNotEmpty: true}}, | ||
} | ||
|
||
tallies, err := dataManager.GetTallies() | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, tallies) | ||
} | ||
|
||
func TestDataManagerGetParamsWithError(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
dataManager := &Manager{ | ||
Logger: *log, | ||
Chains: types.Chains{{Name: "chain"}}, | ||
Fetchers: []fetchersPkg.Fetcher{&fetchersPkg.TestFetcher{WithParamsError: true}}, | ||
} | ||
|
||
params, err := dataManager.GetParams() | ||
require.Error(t, err) | ||
assert.Empty(t, params) | ||
} | ||
|
||
func TestDataManagerGetParamsOk(t *testing.T) { | ||
t.Parallel() | ||
|
||
log := logger.GetNopLogger() | ||
dataManager := &Manager{ | ||
Logger: *log, | ||
Chains: types.Chains{{Name: "chain"}}, | ||
Fetchers: []fetchersPkg.Fetcher{&fetchersPkg.TestFetcher{}}, | ||
} | ||
|
||
params, err := dataManager.GetParams() | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, params) | ||
} |
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
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
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.