当前位置: 首页>>代码示例>>Golang>>正文


Golang assertions.New函数代码示例

本文整理汇总了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))
}
开发者ID:smartystreets,项目名称:clock,代码行数:11,代码来源:clock_test.go

示例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})
}
开发者ID:smartystreets,项目名称:clock,代码行数:11,代码来源:clock_test.go

示例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)
}
开发者ID:smartystreets,项目名称:logging,代码行数:14,代码来源:logging_test.go

示例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)
}
开发者ID:smartystreets,项目名称:logging,代码行数:14,代码来源:logging_test.go

示例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")
	}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:26,代码来源:auth_test.go

示例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})
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go

示例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)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go

示例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)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go

示例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)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:7,代码来源:conversions_test.go

示例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)
	}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:32,代码来源:auth_test.go

示例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)
}
开发者ID:smartystreets,项目名称:logging,代码行数:8,代码来源:logging_test.go

示例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)
}
开发者ID:smartystreets,项目名称:clock,代码行数:9,代码来源:clock_test.go

示例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)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:11,代码来源:conversions_test.go

示例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, ``)
}
开发者ID:kdar,项目名称:idiff,代码行数:11,代码来源:idiff_test.go

示例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")
}
开发者ID:smartystreets,项目名称:logging,代码行数:12,代码来源:logging_test.go


注:本文中的github.com/smartystreets/assertions.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。