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


Golang asserts.NewTestingAssertion函数代码示例

本文整理汇总了Golang中github.com/pellaeon/gots/v3/asserts.NewTestingAssertion函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestingAssertion函数的具体用法?Golang NewTestingAssertion怎么用?Golang NewTestingAssertion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewTestingAssertion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSimpleNoTimeout

// TestSimpleNoTimeout tests a simple scene usage without
// any timeout.
func TestSimpleNoTimeout(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	scn := scene.Start()

	id := scn.ID()
	assert.Length(id, 16)
	err := scn.Store("foo", 4711)
	assert.Nil(err)
	foo, err := scn.Fetch("foo")
	assert.Nil(err)
	assert.Equal(foo, 4711)
	_, err = scn.Fetch("bar")
	assert.True(scene.IsPropNotFoundError(err))
	err = scn.Store("foo", "bar")
	assert.True(scene.IsPropAlreadyExistError(err))
	_, err = scn.Dispose("bar")
	assert.True(scene.IsPropNotFoundError(err))
	foo, err = scn.Dispose("foo")
	assert.Nil(err)
	assert.Equal(foo, 4711)
	_, err = scn.Fetch("foo")
	assert.True(scene.IsPropNotFoundError(err))

	status, err := scn.Status()
	assert.Nil(err)
	assert.Equal(status, scene.Active)

	err = scn.Stop()
	assert.Nil(err)

	status, err = scn.Status()
	assert.Nil(err)
	assert.Equal(status, scene.Over)
}
开发者ID:pellaeon,项目名称:goas,代码行数:36,代码来源:scene_test.go

示例2: TestCleanupNoError

// TestCleanupNoError tests the cleanup of props with
// no errors.
func TestCleanupNoError(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	cleanups := make(map[string]interface{})
	cleanup := func(key string, prop interface{}) error {
		cleanups[key] = prop
		return nil
	}
	scn := scene.Start()

	err := scn.StoreClean("foo", 4711, cleanup)
	assert.Nil(err)
	err = scn.StoreClean("bar", "yadda", cleanup)
	assert.Nil(err)

	foo, err := scn.Dispose("foo")
	assert.Nil(err)
	assert.Equal(foo, 4711)

	err = scn.Stop()
	assert.Nil(err)

	assert.Length(cleanups, 2)
	assert.Equal(cleanups["foo"], 4711)
	assert.Equal(cleanups["bar"], "yadda")
}
开发者ID:pellaeon,项目名称:goas,代码行数:27,代码来源:scene_test.go

示例3: TestEarlyFlag

// TestEarlyFlag tests the signaling before a waiting.
func TestEarlyFlag(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	scn := scene.Start()
	err := scn.Flag("foo")
	assert.Nil(err)

	go func() {
		err := scn.WaitFlag("foo")
		assert.Nil(err)
		err = scn.Store("foo-a", true)
		assert.Nil(err)
	}()
	go func() {
		err := scn.WaitFlag("foo")
		assert.Nil(err)
		err = scn.Store("foo-b", true)
		assert.Nil(err)
	}()

	time.Sleep(100 * time.Millisecond)

	fooA, err := scn.Fetch("foo-a")
	assert.Nil(err)
	assert.Equal(fooA, true)
	fooB, err := scn.Fetch("foo-b")
	assert.Nil(err)
	assert.Equal(fooB, true)

	err = scn.Stop()
	assert.Nil(err)
}
开发者ID:pellaeon,项目名称:goas,代码行数:32,代码来源:scene_test.go

示例4: TestSimpleInactivityTimeout

// TestSimpleInactivityTimeout tests a simple scene usage
// with inactivity timeout.
func TestSimpleInactivityTimeout(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	scn := scene.StartLimited(100*time.Millisecond, 0)

	err := scn.Store("foo", 4711)
	assert.Nil(err)

	for i := 0; i < 5; i++ {
		foo, err := scn.Fetch("foo")
		assert.Nil(err)
		assert.Equal(foo, 4711)
		time.Sleep(50)
	}

	time.Sleep(100 * time.Millisecond)

	foo, err := scn.Fetch("foo")
	assert.True(scene.IsTimeoutError(err))
	assert.Nil(foo)

	status, err := scn.Status()
	assert.True(scene.IsTimeoutError(err))
	assert.Equal(status, scene.Over)

	err = scn.Stop()
	assert.True(scene.IsTimeoutError(err))
}
开发者ID:pellaeon,项目名称:goas,代码行数:29,代码来源:scene_test.go

示例5: TestUUIDVersions

// Test UUID versions.
func TestUUIDVersions(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	ns := identifier.UUIDNamespaceOID()
	// Asserts.
	uuidV1, err := identifier.NewUUIDv1()
	assert.Nil(err)
	assert.Equal(uuidV1.Version(), identifier.UUIDv1)
	assert.Equal(uuidV1.Variant(), identifier.UUIDVariantRFC4122)
	assert.Logf("UUID V1: %v", uuidV1)
	uuidV3, err := identifier.NewUUIDv3(ns, []byte{4, 7, 1, 1})
	assert.Nil(err)
	assert.Equal(uuidV3.Version(), identifier.UUIDv3)
	assert.Equal(uuidV3.Variant(), identifier.UUIDVariantRFC4122)
	assert.Logf("UUID V3: %v", uuidV3)
	uuidV4, err := identifier.NewUUIDv4()
	assert.Nil(err)
	assert.Equal(uuidV4.Version(), identifier.UUIDv4)
	assert.Equal(uuidV4.Variant(), identifier.UUIDVariantRFC4122)
	assert.Logf("UUID V4: %v", uuidV4)
	uuidV5, err := identifier.NewUUIDv5(ns, []byte{4, 7, 1, 1})
	assert.Nil(err)
	assert.Equal(uuidV5.Version(), identifier.UUIDv5)
	assert.Equal(uuidV5.Variant(), identifier.UUIDVariantRFC4122)
	assert.Logf("UUID V5: %v", uuidV5)
}
开发者ID:pellaeon,项目名称:goas,代码行数:26,代码来源:uuid_test.go

示例6: TestTimeContainments

// Test time containments.
func TestTimeContainments(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	// Create some test data.
	ts := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	years := []int{2008, 2009, 2010}
	months := []time.Month{10, 11, 12}
	days := []int{10, 11, 12, 13, 14}
	hours := []int{20, 21, 22, 23}
	minutes := []int{0, 5, 10, 15, 20, 25}
	seconds := []int{0, 15, 30, 45}
	weekdays := []time.Weekday{time.Monday, time.Tuesday, time.Wednesday}

	assert.True(timex.YearInList(ts, years), "Go time in year list.")
	assert.True(timex.YearInRange(ts, 2005, 2015), "Go time in year range.")
	assert.True(timex.MonthInList(ts, months), "Go time in month list.")
	assert.True(timex.MonthInRange(ts, 7, 12), "Go time in month range.")
	assert.True(timex.DayInList(ts, days), "Go time in day list.")
	assert.True(timex.DayInRange(ts, 5, 15), "Go time in day range .")
	assert.True(timex.HourInList(ts, hours), "Go time in hour list.")
	assert.True(timex.HourInRange(ts, 20, 31), "Go time in hour range .")
	assert.True(timex.MinuteInList(ts, minutes), "Go time in minute list.")
	assert.True(timex.MinuteInRange(ts, 0, 5), "Go time in minute range .")
	assert.True(timex.SecondInList(ts, seconds), "Go time in second list.")
	assert.True(timex.SecondInRange(ts, 0, 5), "Go time in second range .")
	assert.True(timex.WeekdayInList(ts, weekdays), "Go time in weekday list.")
	assert.True(timex.WeekdayInRange(ts, time.Monday, time.Friday), "Go time in weekday range .")
}
开发者ID:pellaeon,项目名称:goas,代码行数:28,代码来源:timex_test.go

示例7: TestFlagTimeout

// TestFlagTimeout tests the waiting for a signal with
// a timeout.
func TestFlagTimeout(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, false)
	scn := scene.Start()

	go func() {
		err := scn.WaitFlag("foo")
		assert.Nil(err)
		err = scn.Store("foo-a", true)
		assert.Nil(err)
	}()
	go func() {
		err := scn.WaitFlagLimited("foo", 50*time.Millisecond)
		assert.True(scene.IsWaitedTooLongError(err))
		err = scn.Store("foo-b", true)
		assert.Nil(err)
	}()

	time.Sleep(100 * time.Millisecond)

	err := scn.Flag("foo")
	assert.Nil(err)

	fooA, err := scn.Fetch("foo-a")
	assert.Nil(err)
	assert.Equal(fooA, true)
	fooB, err := scn.Fetch("foo-b")
	assert.Nil(err)
	assert.Equal(fooB, true)

	err = scn.Stop()
	assert.Nil(err)
}
开发者ID:pellaeon,项目名称:goas,代码行数:34,代码来源:scene_test.go

示例8: TestEtmMonitor

// Test of the ETM monitor.
func TestEtmMonitor(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	// Generate measurings.
	for i := 0; i < 500; i++ {
		n := rand.Intn(10)
		id := fmt.Sprintf("mp:task:%d", n)
		m := monitoring.BeginMeasuring(id)
		work(n * 5000)
		m.EndMeasuring()
	}
	// Need some time to let that backend catch up queued mesurings.
	time.Sleep(time.Millisecond)
	// Asserts.
	mp, err := monitoring.ReadMeasuringPoint("foo")
	assert.ErrorMatch(err, `\[MONITORING:.*\] measuring point "foo" does not exist`, "reading non-existent measuring point")
	mp, err = monitoring.ReadMeasuringPoint("mp:task:5")
	assert.Nil(err, "No error expected.")
	assert.Equal(mp.Id, "mp:task:5", "should get the right one")
	assert.True(mp.Count > 0, "should be measured several times")
	assert.Match(mp.String(), `Measuring Point "mp:task:5" \(.*\)`, "string representation should look fine")
	monitoring.MeasuringPointsDo(func(mp *monitoring.MeasuringPoint) {
		assert.Match(mp.Id, "mp:task:[0-9]", "id has to match the pattern")
		assert.True(mp.MinDuration <= mp.AvgDuration && mp.AvgDuration <= mp.MaxDuration,
			"avg should be somewhere between min and max")
	})
}
开发者ID:pellaeon,项目名称:goas,代码行数:27,代码来源:monitoring_test.go

示例9: TestSepIdentifier

// Test the creation of identifiers based on parts with defined seperators.
func TestSepIdentifier(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)

	id := identifier.SepIdentifier("+", 1, "oNe", 2, "TWO", "3", "ÄÖÜ")
	assert.Equal(id, "1+one+2+two+3+äöü", "wrong SepIdentifier() result")

	id = identifier.LimitedSepIdentifier("+", true, "     ", 1, "oNe", 2, "TWO", "3", "ÄÖÜ", "Four", "+#-:,")
	assert.Equal(id, "1+one+2+two+3+four", "wrong LimitedSepIdentifier() result")
}
开发者ID:pellaeon,项目名称:goas,代码行数:10,代码来源:identifier_test.go

示例10: TestLevel

// Test log level.
func TestLevel(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)

	logger.SetLevel(logger.LevelDebug)
	assert.Equal(logger.Level(), logger.LevelDebug, "Level debug.")
	logger.SetLevel(logger.LevelCritical)
	assert.Equal(logger.Level(), logger.LevelCritical, "Level critical.")
	logger.SetLevel(logger.LevelDebug)
	assert.Equal(logger.Level(), logger.LevelDebug, "Level debug.")
}
开发者ID:pellaeon,项目名称:goas,代码行数:11,代码来源:logger_test.go

示例11: TestIdentifier

// Test the creation of identifiers based on parts.
func TestIdentifier(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)

	// Identifier.
	id := identifier.Identifier("One", 2, "three four")
	assert.Equal(id, "one:2:three-four", "wrong Identifier() result")

	id = identifier.Identifier(2011, 6, 22, "One, two, or  three things.")
	assert.Equal(id, "2011:6:22:one-two-or-three-things", "wrong Identifier() result")
}
开发者ID:pellaeon,项目名称:goas,代码行数:11,代码来源:identifier_test.go

示例12: TestUUIDByHex

// Test creating UUIDs from hex strings.
func TestUUIDByHex(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	// Asserts.
	_, err := identifier.NewUUIDByHex("ffff")
	assert.ErrorMatch(err, `\[IDENTIFIER:.*\] invalid length of hex string, has to be 32`)
	_, err = identifier.NewUUIDByHex("012345678901234567890123456789zz")
	assert.ErrorMatch(err, `\[IDENTIFIER:.*\] invalid value of hex string: .*`)
	_, err = identifier.NewUUIDByHex("012345678901234567890123456789ab")
	assert.Nil(err)
}
开发者ID:pellaeon,项目名称:goas,代码行数:11,代码来源:uuid_test.go

示例13: TestGetSetLevel

// Test log level.
func TestGetSetLevel(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)

	logger.SetLevel(logger.LevelDebug)
	assert.Equal(logger.Level(), logger.LevelDebug)
	logger.SetLevel(logger.LevelCritical)
	assert.Equal(logger.Level(), logger.LevelCritical)
	logger.SetLevel(logger.LevelDebug)
	assert.Equal(logger.Level(), logger.LevelDebug)
}
开发者ID:pellaeon,项目名称:goas,代码行数:11,代码来源:logger_test.go

示例14: TestInternalPanic

// Test the behavior after an internal panic.
func TestInternalPanic(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	// Register monitoring func with panic.
	monitoring.Register("panic", func() (string, error) { panic("ouch"); return "panic", nil })
	// Need some time to let that backend catch up queued registering.
	time.Sleep(time.Millisecond)
	// Asserts.
	dsv, err := monitoring.ReadStatus("panic")
	assert.Empty(dsv, "no dynamic status value")
	assert.ErrorMatch(err, `\[MONITORING:.*\] monitor backend panicked`, "monitor restarted due to panic")
}
开发者ID:pellaeon,项目名称:goas,代码行数:12,代码来源:monitoring_test.go

示例15: TestDeferredError

// Test an error in a deferred function inside the loop.
func TestDeferredError(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	done := false
	l := loop.Go(generateDeferredErrorBackend(&done))

	assert.ErrorMatch(l.Stop(), "deferred error", "error has to be 'deferred error'")
	assert.True(done, "backend has done")

	status, _ := l.Error()

	assert.Equal(loop.Stopped, status, "loop is stopped")
}
开发者ID:pellaeon,项目名称:goas,代码行数:13,代码来源:loop_test.go


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