Files
gocryptotrader/cmd/exchange_template/exchange_template_test.go
Rauno Ots ee55ae5d0f Config: refactor config file loaders (#577)
* Config: fix don't create empty dir when resolving path

* Config: refactor config file loaders

* add a layer of abstraction so that config can be loaded from non-files
* use io.Reader / io.Writer abstraction to separate data operations from
file operations
* remove dryrun option from SaveConfig - now it always saves

* rename read and save methods to mention file operations

* log error when encryption prompt fails

* as the user didn't make a choice, we'd prompt again next time the file
is loaded
* add file.Writer tests
* skip permissions test for windows

* defer creating the writer on save to the last moment

* this avoids truncating file when there is error with password prompt
* add a test

* tests with StdIn cannot run in parallel
2020-11-04 11:46:13 +11:00

75 lines
1.5 KiB
Go

package main
import (
"os"
"path/filepath"
"testing"
"github.com/thrasher-corp/gocryptotrader/config"
)
func TestCheckExchangeName(t *testing.T) {
tester := []struct {
Name string
ErrExpected error
}{
{
Name: "test exch",
ErrExpected: errInvalidExchangeName,
},
{
ErrExpected: errInvalidExchangeName,
},
{
Name: " ",
ErrExpected: errInvalidExchangeName,
},
{
Name: "m",
ErrExpected: errInvalidExchangeName,
},
{
Name: "mu",
ErrExpected: errInvalidExchangeName,
},
{
Name: "testexch",
},
}
for x := range tester {
if r := checkExchangeName(tester[x].Name); r != tester[x].ErrExpected {
t.Errorf("test: %d unexpected result", x)
}
}
}
func TestNewExchange(t *testing.T) {
testExchangeName := "testexch"
testExchangeDir := filepath.Join(targetPath, testExchangeName)
if err := makeExchange(&exchange{
Name: testExchangeName,
REST: true,
WS: true,
}); err != nil {
t.Error(err)
}
if err := os.RemoveAll(testExchangeDir); err != nil {
t.Errorf("unable to remove dir: %s, manual removal required", err)
}
cfg := config.GetConfig()
if err := cfg.LoadConfig(exchangeConfigPath, true); err != nil {
t.Fatal(err)
}
if success := cfg.RemoveExchange(testExchangeName); !success {
t.Fatalf("unable to remove exchange config for %s, manual removal required\n",
testExchangeName)
}
if err := cfg.SaveConfigToFile(exchangeConfigPath); err != nil {
t.Fatal(err)
}
}