-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currency: Use mock provider for tests
- Loading branch information
Showing
3 changed files
with
56 additions
and
22 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,39 @@ | ||
package currency | ||
|
||
import ( | ||
"math/rand" | ||
"strings" | ||
|
||
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider" | ||
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/base" | ||
) | ||
|
||
type MockProvider struct{} | ||
|
||
func newMockProvider() *forexprovider.ForexProviders { | ||
p := &MockProvider{} | ||
c, _ := p.GetSupportedCurrencies() | ||
return &forexprovider.ForexProviders{ | ||
base.FXHandler{ | ||
Primary: base.Provider{ | ||
Provider: p, | ||
SupportedCurrencies: c, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (m *MockProvider) GetName() string { return "MockProvider" } | ||
func (m *MockProvider) Setup(base.Settings) error { return nil } | ||
func (m *MockProvider) IsEnabled() bool { return true } | ||
func (m *MockProvider) IsPrimaryProvider() bool { return true } | ||
func (m *MockProvider) GetSupportedCurrencies() ([]string, error) { | ||
return storage.defaultFiatCurrencies.Strings(), nil | ||
} | ||
func (m *MockProvider) GetRates(baseCurrency, symbols string) (map[string]float64, error) { | ||
c := map[string]float64{} | ||
for _, s := range strings.Split(symbols, ",") { | ||
c[baseCurrency+s] = 1/1 + rand.Float64() // The year is 2027; The USD is nearly worthless. The world reserve currency is eggs. | ||
} | ||
return c, 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