本文整理汇总了Golang中github.com/smartystreets/assertions.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNilReferencesForwardToStandardBehavior
func TestNilReferencesForwardToStandardBehavior(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now := time.Now().UTC()
now2 := thing.CurrentTime()
thing.Sleep(time.Millisecond * 100)
now3 := thing.CurrentTime()
assertions.New(t).So(now, should.HappenWithin, time.Millisecond, now2)
assertions.New(t).So(now3, should.HappenOnOrAfter, now2.Add(time.Millisecond*100))
}
示例2: TestActualSleeperInstanceIsUsefulForTesting
func TestActualSleeperInstanceIsUsefulForTesting(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now := time.Now().UTC()
thing.sleeper = StayAwake()
thing.Sleep(time.Hour)
now2 := thing.CurrentTime()
assertions.New(t).So(now, should.HappenWithin, time.Millisecond, now2)
assertions.New(t).So(thing.sleeper.Naps, should.Resemble, []time.Duration{time.Hour})
}
示例3: TestLoggingWithLoggerCapturesOutput
func TestLoggingWithLoggerCapturesOutput(t *testing.T) {
out := new(bytes.Buffer)
log.SetOutput(out)
log.SetFlags(0)
defer log.SetOutput(os.Stdout)
defer log.SetFlags(log.LstdFlags)
thing := new(ThingUnderTest)
thing.log = Capture()
thing.Action()
assertions.New(t).So(thing.log.Log.String(), should.Equal, "Hello, World!\n")
assertions.New(t).So(out.Len(), should.Equal, 0)
}
示例4: TestLoggingWithDiscard
func TestLoggingWithDiscard(t *testing.T) {
out := new(bytes.Buffer)
log.SetOutput(out)
log.SetFlags(0)
defer log.SetOutput(os.Stdout)
defer log.SetFlags(log.LstdFlags)
thing := new(ThingUnderTest)
thing.log = Discard()
thing.Action()
assertions.New(t).So(thing.log.Log.Len(), should.Equal, 0)
assertions.New(t).So(out.Len(), should.Equal, 0)
}
示例5: TestParseAuthServer
func TestParseAuthServer(t *testing.T) {
a := assertions.New(t)
{
srv, err := parseAuthServer("https://user:[email protected]/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "https://account.thethingsnetwork.org")
a.So(srv.username, assertions.ShouldEqual, "user")
a.So(srv.password, assertions.ShouldEqual, "pass")
}
{
srv, err := parseAuthServer("https://[email protected]/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "https://account.thethingsnetwork.org")
a.So(srv.username, assertions.ShouldEqual, "user")
}
{
srv, err := parseAuthServer("http://account.thethingsnetwork.org/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "http://account.thethingsnetwork.org")
}
{
srv, err := parseAuthServer("http://localhost:9090/")
a.So(err, assertions.ShouldBeNil)
a.So(srv.url, assertions.ShouldEqual, "http://localhost:9090")
}
}
示例6: TestBytes
func TestBytes(t *testing.T) {
a := assertions.New(t)
a.So(FormatBytes([]byte{0x12, 0x34, 0xcd, 0xef}), assertions.ShouldEqual, "1234CDEF")
i64, err := ParseBytes("1234CDEF")
a.So(err, assertions.ShouldBeNil)
a.So(i64, assertions.ShouldResemble, []byte{0x12, 0x34, 0xcd, 0xef})
}
示例7: TestUint64
func TestUint64(t *testing.T) {
a := assertions.New(t)
a.So(FormatUint64(123456), assertions.ShouldEqual, "123456")
i64, err := ParseUint64("123456")
a.So(err, assertions.ShouldBeNil)
a.So(i64, assertions.ShouldEqual, 123456)
}
示例8: TestInt64
func TestInt64(t *testing.T) {
a := assertions.New(t)
a.So(FormatInt64(-123456), assertions.ShouldEqual, "-123456")
i64, err := ParseInt64("-123456")
a.So(err, assertions.ShouldBeNil)
a.So(i64, assertions.ShouldEqual, -123456)
}
示例9: TestFloat64
func TestFloat64(t *testing.T) {
a := assertions.New(t)
a.So(FormatFloat64(123.456), assertions.ShouldEqual, "123.456")
f64, err := ParseFloat64("123.456")
a.So(err, assertions.ShouldBeNil)
a.So(f64, assertions.ShouldEqual, 123.456)
}
示例10: TestExchangeAppKeyForToken
func TestExchangeAppKeyForToken(t *testing.T) {
for _, env := range strings.Split("ACCOUNT_SERVER_PROTO ACCOUNT_SERVER_USERNAME ACCOUNT_SERVER_PASSWORD ACCOUNT_SERVER_URL APP_ID APP_TOKEN", " ") {
if os.Getenv(env) == "" {
t.Skipf("Skipping auth server test: %s configured", env)
}
}
a := assertions.New(t)
c := new(Component)
c.Config.KeyDir = os.TempDir()
c.Config.AuthServers = map[string]string{
"ttn-account-preview": fmt.Sprintf("%s://%s:%[email protected]%s",
os.Getenv("ACCOUNT_SERVER_PROTO"),
os.Getenv("ACCOUNT_SERVER_USERNAME"),
os.Getenv("ACCOUNT_SERVER_PASSWORD"),
os.Getenv("ACCOUNT_SERVER_URL"),
),
}
c.initAuthServers()
{
token, err := c.ExchangeAppKeyForToken(os.Getenv("APP_ID"), "ttn-account-preview."+os.Getenv("APP_TOKEN"))
a.So(err, assertions.ShouldBeNil)
a.So(token, assertions.ShouldNotBeEmpty)
}
{
token, err := c.ExchangeAppKeyForToken(os.Getenv("APP_ID"), os.Getenv("APP_TOKEN"))
a.So(err, assertions.ShouldBeNil)
a.So(token, assertions.ShouldNotBeEmpty)
}
}
示例11: TestLogCallsAreCounted
func TestLogCallsAreCounted(t *testing.T) {
thing := new(ThingUnderTest)
thing.log = Capture()
for x := 0; x < 10; x++ {
thing.Action()
}
assertions.New(t).So(thing.log.Calls, should.Equal, 10)
}
示例12: TestActualClockInstanceIsUsefulForTesting
func TestActualClockInstanceIsUsefulForTesting(t *testing.T) {
t.Parallel()
thing := new(ThingUnderTest)
now := time.Now().UTC()
thing.clock = Freeze(now)
now2 := thing.CurrentTime()
assertions.New(t).So(now, should.Resemble, now2)
}
示例13: TestBool
func TestBool(t *testing.T) {
a := assertions.New(t)
a.So(FormatBool(true), assertions.ShouldEqual, "true")
b, err := ParseBool("true")
a.So(err, assertions.ShouldBeNil)
a.So(b, assertions.ShouldEqual, true)
a.So(FormatBool(false), assertions.ShouldEqual, "false")
b, err = ParseBool("false")
a.So(err, assertions.ShouldBeNil)
a.So(b, assertions.ShouldEqual, false)
}
示例14: TestSimple
func TestSimple(t *testing.T) {
a := assertions.New(t)
diff, equal := Diff("hey", "there")
a.So(equal, should.BeFalse)
a.So(FormatTest(diff), should.Equal, `string: got: "there", expected: "hey"`)
diff, equal = Diff("hey", "hey")
a.So(equal, should.BeTrue)
a.So(FormatTest(diff), should.Equal, ``)
}
示例15: TestLoggingWithNilReferenceProducesTraditionalBehavior
func TestLoggingWithNilReferenceProducesTraditionalBehavior(t *testing.T) {
out := new(bytes.Buffer)
log.SetOutput(out)
log.SetFlags(0)
defer log.SetOutput(os.Stdout)
defer log.SetFlags(log.LstdFlags)
thing := new(ThingUnderTest)
thing.Action()
assertions.New(t).So(out.String(), should.Equal, "Hello, World!\n")
}