groupme-lib/data_types_test.go

62 lines
1.5 KiB
Go
Raw Normal View History

// Package groupme defines a client capable of executing API commands for the GroupMe chat service
package groupme
import (
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type DataTypesSuite struct {
suite.Suite
}
func (s *DataTypesSuite) TestID_Valid_True() {
var id ID = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
s.Assert().True(id.Valid())
}
func (s *DataTypesSuite) TestID_Valid_False() {
var id ID = "`~!@#$%^&*()_-+={[}]:;\"'<,>.?/|\\"
s.Assert().False(id.Valid())
}
func (s *DataTypesSuite) TestTimestamp_FromTime() {
t := time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
expected := Timestamp(0)
actual := FromTime(t)
s.Assert().EqualValues(expected, actual)
}
func (s *DataTypesSuite) TestTimestamp_ToTime() {
t := Timestamp(0)
expected := time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
actual := t.ToTime()
s.Assert().EqualValues(expected, actual)
}
func (s *DataTypesSuite) TestPhoneNumber_Valid_True() {
var pn PhoneNumber = "+1 0123456789"
s.Assert().True(pn.Valid())
}
func (s *DataTypesSuite) TestPhoneNumber_Valid_NoPlus() {
var pn PhoneNumber = "1 0123456789"
s.Assert().False(pn.Valid())
}
func (s *DataTypesSuite) TestPhoneNumber_Valid_NoSpace() {
var pn PhoneNumber = "+10123456789"
s.Assert().False(pn.Valid())
}
func (s *DataTypesSuite) TestPhoneNumber_Valid_BadLength() {
var pn PhoneNumber = "+1 01234567890"
s.Assert().False(pn.Valid())
}
func TestDataTypesSuite(t *testing.T) {
suite.Run(t, new(DataTypesSuite))
}