當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。