storj/private/currency/microunit_test.go
Jeff Wendling 9bd0bd0c24 private/currency: add strictcsv support to microunit
Change-Id: Iad2f6a07f189f2faa1d13bdb82dfa320921f6938
2020-03-31 14:57:04 -06:00

41 lines
827 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package currency
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/strictcsv"
)
func TestMicroUnitToFloatString(t *testing.T) {
require.Equal(t, "1.002332", NewMicroUnit(1002332).FloatString())
}
func TestMicroUnitFromFloatString(t *testing.T) {
m, err := MicroUnitFromFloatString("0.012340")
require.NoError(t, err)
require.Equal(t, NewMicroUnit(12340), m)
}
func TestMicroUnitCSV(t *testing.T) {
type row struct {
Foo MicroUnit `csv:"foo"`
Bar MicroUnit `csv:"bar"`
}
exp := row{
Foo: NewMicroUnit(1),
Bar: NewMicroUnit(2),
}
csv, err := strictcsv.MarshalString(exp)
require.NoError(t, err)
var got row
require.NoError(t, strictcsv.UnmarshalString(csv, &got))
require.Equal(t, exp, got)
}