Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKochetov007 committed Jan 8, 2024
1 parent 9446455 commit d9a5e7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/common/data/instrument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package data_test
import (
"testing"
"time"
goErrors "errors"

"xoney/common/data"
"xoney/errors"
Expand Down Expand Up @@ -34,14 +33,17 @@ func TestSymbolExchange(t *testing.T) {
}

func TestTimeFrameIncorrect(t *testing.T) {
duration := time.Duration(-1234)
duration := time.Duration(-time.Hour)
_, err := data.NewTimeFrame(duration, "incorrect tf")

expected := errors.NewIncorrectDurationError(time.Duration(-1234))
expected := "invalid duration: -1h0m0s."

if !goErrors.Is(err, expected) {
if err.Error() != expected {
t.Errorf("Expected IncorrectDurationError, got: %s", err.Error())
}
if _, ok := err.(errors.IncorrectDurationError); !ok {
t.Errorf("Expected IncorrectDurationError, got: %v", err)
}
}

func Daily() data.TimeFrame {
Expand Down
12 changes: 12 additions & 0 deletions test/common/portfolio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common_test

import (
"testing"
"strings"

"xoney/common"
"xoney/common/data"
Expand Down Expand Up @@ -80,7 +81,18 @@ func TestPortfolioTotal(t *testing.T) {
if err.Error() != expected.Error() {
t.Errorf("Expected MissingCurrencyError, got: %v", err)
}
if strings.Contains(err.Error(), ", ") {
t.Errorf("Unexpected ', ' in error, got: %v", err)
}

// Without both currencies
delete(prices, eth)

_, err = portfolio.Total(prices)

if !strings.Contains(err.Error(), ", ") {
t.Errorf("Expected ', ' in error, got: %v", err)
}
}

func TestPortfolioBalance(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions test/exchange/connetor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ func TestMarginSimulator_CancelOrder_NonExistingOrder(t *testing.T) {
if !goErrors.Is(err, expectedError) {
t.Errorf("Expected NoLimitOrderError, got: %v", err)
}
if err.Error() != "there is no such limit order with ID: 123." {
t.Errorf("Incorrect text of error: %v", err)
}
}

func TestMarginSimulator_CancelOrder_ExistingOrder(t *testing.T) {
Expand Down

0 comments on commit d9a5e7c

Please sign in to comment.