carbon/database_test.go
gouguoyin@juzifenqi.com 8b562c758b optimize unit testing
2022-04-14 10:40:28 +08:00

37 lines
660 B
Go
Executable File

package carbon
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCarbon_Scan(t *testing.T) {
c := NewCarbon()
err := c.Scan(time.Now())
assert.Nil(t, err)
assert.Equal(t, c.ToDateTimeString(), Now().ToDateTimeString())
}
func TestCarbon_Value(t *testing.T) {
c := Now()
v, err := c.Value()
assert.Nil(t, err)
assert.Equal(t, v, c.time)
}
func TestError_Scan(t *testing.T) {
c, v := NewCarbon(), "xxx"
err := c.Scan(v)
assert.Equal(t, err, fmt.Errorf("can not convert %v to carbon", v))
}
func TestError_Value(t *testing.T) {
c := Parse("")
v, err := c.Value()
assert.Nil(t, err)
assert.Equal(t, v, nil)
}