當前位置: 首頁>>代碼示例>>Golang>>正文


Golang asserts.NewTestingAsserts函數代碼示例

本文整理匯總了Golang中cgl/tideland/biz/asserts.NewTestingAsserts函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTestingAsserts函數的具體用法?Golang NewTestingAsserts怎麽用?Golang NewTestingAsserts使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewTestingAsserts函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestEventBox

// TestBox tests the box usage.
func TestEventBox(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	inbox := newBox()

	assert.Equal(inbox.len(), 0, "box is empty")

	inbox.push(EventMessage(EmptyPayload, "Event", 1))
	inbox.push(EventMessage(EmptyPayload, "Event", 2))
	inbox.push(EventMessage(EmptyPayload, "Event", 3))

	assert.Equal(inbox.len(), 3, "box has right length")
	assert.Equal(inbox.pop().event.Topic(), Id("Event", 1), "first event")
	assert.Equal(inbox.pop().event.Topic(), Id("Event", 2), "second event")
	assert.Equal(inbox.pop().event.Topic(), Id("Event", 3), "third event")

	go func() {
		assert.Equal(inbox.pop().event.Topic(), Id("Event", 4), "fourth event")

		inbox.push(EventMessage(EmptyPayload, "Event", 5))
	}()

	inbox.push(EventMessage(EmptyPayload, "Event", 4))
	time.Sleep(100 * time.Millisecond)
	assert.Equal(inbox.pop().event.Topic(), Id("Event", 5), "fifth event")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:26,代碼來源:internal_test.go

示例2: TestHookRPC

func TestHookRPC(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	// Create the UI to test
	h := new(packer.MockHook)

	// Serve
	server := rpc.NewServer()
	RegisterHook(server, h)
	address := serveSingleConn(server)

	// Create the client over RPC and run some methods to verify it works
	client, err := rpc.Dial("tcp", address)
	assert.Nil(err, "should be able to connect")

	hClient := Hook(client)

	// Test Run
	ui := &testUi{}
	hClient.Run("foo", ui, nil, 42)
	assert.True(h.RunCalled, "run should be called")

	// Test Cancel
	hClient.Cancel()
	assert.True(h.CancelCalled, "cancel should be called")
}
開發者ID:B-Rich,項目名稱:packer,代碼行數:26,代碼來源:hook_test.go

示例3: TestEtmMonitor

// Test of the ETM monitor.
func TestEtmMonitor(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	// Generate measurings.
	for i := 0; i < 500; i++ {
		n := rand.Intn(10)
		id := fmt.Sprintf("mp:task:%d", n)
		m := BeginMeasuring(id)
		work(n * 5000)
		m.EndMeasuring()
	}
	// Need some time to let that backend catch up queued mesurings.
	time.Sleep(1e7)
	// Asserts.
	mp, err := ReadMeasuringPoint("foo")
	assert.ErrorMatch(err, `measuring point "foo" does not exist`, "Reading non-existent measuring point.")
	mp, err = 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.")
	MeasuringPointsDo(func(mp *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:rpeer-denis,項目名稱:tcgl,代碼行數:27,代碼來源:monitoring_test.go

示例4: TestBlockDevice

func TestBlockDevice(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	ec2Mapping := []ec2.BlockDeviceMapping{
		ec2.BlockDeviceMapping{
			DeviceName:          "/dev/sdb",
			VirtualName:         "ephemeral0",
			SnapshotId:          "snap-1234",
			VolumeType:          "standard",
			VolumeSize:          8,
			DeleteOnTermination: true,
			IOPS:                1000,
		},
	}

	blockDevice := BlockDevice{
		DeviceName:          "/dev/sdb",
		VirtualName:         "ephemeral0",
		SnapshotId:          "snap-1234",
		VolumeType:          "standard",
		VolumeSize:          8,
		DeleteOnTermination: true,
		IOPS:                1000,
	}

	blockDevices := BlockDevices{
		AMIMappings:    []BlockDevice{blockDevice},
		LaunchMappings: []BlockDevice{blockDevice},
	}

	assert.Equal(ec2Mapping, blockDevices.BuildAMIDevices(), "should match output")
	assert.Equal(ec2Mapping, blockDevices.BuildLaunchDevices(), "should match output")
}
開發者ID:rgarcia,項目名稱:packer,代碼行數:33,代碼來源:block_device_test.go

示例5: TestProvisionerRPC

func TestProvisionerRPC(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	// Create the interface to test
	p := new(testProvisioner)

	// Start the server
	server := rpc.NewServer()
	RegisterProvisioner(server, p)
	address := serveSingleConn(server)

	// Create the client over RPC and run some methods to verify it works
	client, err := rpc.Dial("tcp", address)
	assert.Nil(err, "should be able to connect")

	// Test Prepare
	config := 42
	pClient := Provisioner(client)
	pClient.Prepare(config)
	assert.True(p.prepareCalled, "prepare should be called")
	assert.Equal(p.prepareConfigs, []interface{}{42}, "prepare should be called with right arg")

	// Test Provision
	ui := &testUi{}
	comm := new(packer.MockCommunicator)
	pClient.Provision(ui, comm)
	assert.True(p.provCalled, "provision should be called")

	p.provUi.Say("foo")
	assert.True(ui.sayCalled, "say should be called")
}
開發者ID:ramonvanalteren,項目名稱:packer,代碼行數:31,代碼來源:provisioner_test.go

示例6: TestDuration

// TestDuration tests time.Duration values.
func TestDuration(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	provider := config.NewMapConfigurationProvider()
	cfg := config.New(provider)

	cfg.Set("alpha", "0")
	cfg.Set("bravo", 5*time.Second)
	cfg.Set("charlie", "4711ms")

	// Successful gets.
	value, err := cfg.GetDuration("alpha")
	assert.Nil(err, "No error.")
	assert.Equal(value, 0*time.Second, "Right value 'alpha' returned.")
	value, err = cfg.GetDuration("bravo")
	assert.Nil(err, "No error.")
	assert.Equal(value, 5*time.Second, "Right value 'bravo' returned.")
	value, err = cfg.GetDuration("charlie")
	assert.Nil(err, "No error.")
	assert.Equal(value, 4711*time.Millisecond, "Right value 'charlie' returned.")

	// Illegal format.
	cfg.Set("illegal-format", true)
	_, err = cfg.GetDuration("illegal-format")
	assert.ErrorMatch(err, `invalid type "duration" for "true" (.*)`, "Right error returned.")

	// Non-existing key.
	_, err = cfg.GetDuration("non-existing-key")
	assert.ErrorMatch(err, `key "non-existing-key" does not exist`, "Right error returned.")

	// Non-existing key with default.
	value, err = cfg.GetDurationDefault("non-existing-key", 5*time.Hour)
	assert.Nil(err, "No error.")
	assert.Equal(value, 5*time.Hour, "Right value 'non-existing-key' returned.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:35,代碼來源:config_test.go

示例7: TestFloat64

// TestFloat64 tests float64 values.
func TestFloat64(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	provider := config.NewMapConfigurationProvider()
	cfg := config.New(provider)

	cfg.Set("alpha", 4711)
	cfg.Set("bravo", -47.11)
	cfg.Set("charlie", 0.0)

	// Successful gets.
	value, err := cfg.GetFloat64("alpha")
	assert.Nil(err, "No error.")
	assert.Equal(value, float64(4711), "Right value 'alpha' returned.")
	value, err = cfg.GetFloat64("bravo")
	assert.Nil(err, "No error.")
	assert.Equal(value, float64(-47.11), "Right value 'bravo' returned.")
	value, err = cfg.GetFloat64("charlie")
	assert.Nil(err, "No error.")
	assert.Equal(value, float64(0), "Right value 'charlie' returned.")

	// Illegal format.
	cfg.Set("illegal-format", true)
	_, err = cfg.GetFloat64("illegal-format")
	assert.ErrorMatch(err, `invalid type "float64" for "true" (.*)`, "Right error returned.")

	// Non-existing key.
	_, err = cfg.GetFloat64("non-existing-key")
	assert.ErrorMatch(err, `key "non-existing-key" does not exist`, "Right error returned.")

	// Non-existing key with default.
	value, err = cfg.GetFloat64Default("non-existing-key", 47.11)
	assert.Nil(err, "No error.")
	assert.Equal(value, float64(47.11), "Right value 'non-existing-key' returned.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:35,代碼來源:config_test.go

示例8: TestSMLNegativeReading

// Test negative reading.
func TestSMLNegativeReading(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	sml := "{Foo {bar:1 Yadda {test} {} 1} {bar:2 Yadda 2}}"
	builder := markup.NewNodeBuilder()
	err := markup.ReadSML(strings.NewReader(sml), builder)
	assert.ErrorMatch(err, "invalid rune.*", "Invalid rune should be found.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:8,代碼來源:markup_test.go

示例9: TestIntList

// TestIntList tests the usage of int lists.
func TestIntList(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	values := worm.Ints{1, 5, 6, 2, 5, 2, 9}
	i := worm.NewIntList(values)

	// Test length.
	assert.Length(i, 7, "correct length")

	// Tast retrieving the values.
	values = i.Values()
	assert.Length(values, 7, "correct length")
	assert.Equal(values, worm.Ints{1, 5, 6, 2, 5, 2, 9}, "values are right")

	// Tast retrieving the values sorted.
	values = i.SortedValues()
	assert.Length(values, 7, "correct length")
	assert.Equal(values, worm.Ints{1, 2, 2, 5, 5, 6, 9}, "values are right")

	// Test containing test.
	// assert.True(i.Contains(), "emtpy values are ok")
	// assert.True(i.Contains(6, 5), "values detected")
	// assert.False(i.Contains(1, 2, 7), "invalid values recognized")

	// Test appending more values.
	av := worm.Ints{2, 6, 1001, 1010, 1005}
	ai := i.Append(av)
	assert.Length(ai, i.Len()+5, "five more values in the new list")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:29,代碼來源:worm_test.go

示例10: TestStripTags

func TestStripTags(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	in := "<p>The quick brown <b>fox</b> jumps over the lazy <em>dog</em>.</p>"
	out, err := net.StripTags(in, true, false)
	assert.Nil(err, "No error during stripping.")
	assert.Equal(out, "The quick brown fox jumps over the lazy dog .", "Tags have been removed.")

	in = "<p>The quick brown <b>fox</b> jumps over the lazy <em>dog.</p>"
	out, err = net.StripTags(in, true, false)
	assert.ErrorMatch(err, `XML syntax error on line 1.*`, "Error in document detected.")

	in = "<p>The quick brown <b>fox</b> jumps over the lazy <em>dog.</p>"
	out, err = net.StripTags(in, false, false)
	assert.Nil(err, "No error during stripping.")
	assert.Equal(out, "The quick brown fox jumps over the lazy dog.", "Tags have been removed.")

	in = "<p>The quick brown <b>fox &amp; goose</b> jump over the lazy &lt;em&gt;dog&lt;/em&gt;.</p>"
	out, err = net.StripTags(in, true, false)
	assert.Nil(err, "No error during stripping.")
	assert.Equal(out, "The quick brown fox & goose jump over the lazy <em>dog</em>.", "Tags have been removed.")

	in = "<p>The quick brown <b>fox &amp;amp; goose</b> jump over the lazy &lt;em&gt;dog&lt;/em&gt;.</p>"
	out, err = net.StripTags(in, true, true)
	assert.Nil(err, "No error during stripping.")
	assert.Equal(out, "The quick brown fox & goose jump over the lazy dog .", "Tags have been removed.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:27,代碼來源:net_test.go

示例11: TestEncodeDecode

// Test encoding and decoding a doc.
func TestEncodeDecode(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	a1 := &atom.Feed{
		XMLNS:   atom.XMLNS,
		Id:      "http://tideland.biz/pkg/net/atom",
		Title:   &atom.Text{"Test Encode/Decode", "", "text"},
		Updated: atom.ComposeTime(time.Now()),
		Entries: []*atom.Entry{
			{
				Id:      "http://tideland.bi/pkg/net/atom/entry-1",
				Title:   &atom.Text{"Entry 1", "", "text"},
				Updated: atom.ComposeTime(time.Now()),
			},
			{
				Id:      "http://tideland.bi/pkg/net/atom/entry-2",
				Title:   &atom.Text{"Entry 2", "", "text"},
				Updated: atom.ComposeTime(time.Now()),
			},
		},
	}
	b := &bytes.Buffer{}

	err := atom.Encode(b, a1)
	assert.Nil(err, "Encoding returns no error.")
	assert.Substring(b.String(), `<title type="text">Test Encode/Decode</title>`, "Title has been encoded correctly.")

	a2, err := atom.Decode(b)
	assert.Nil(err, "Decoding returns no error.")
	assert.Equal(a2.Title.Text, "Test Encode/Decode", "Title has been decoded correctly.")
	assert.Length(a2.Entries, 2, "Decoded feed has the right number of items.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:32,代碼來源:atom_test.go

示例12: TestCounterBehavior

// TestCounterBehavior tests the counting of events
// by the counter behavior.
func TestCounterBehavior(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	cf := func(e Event) []string {
		return []string{e.Topic()}
	}
	env := NewEnvironment("counter-behavior")
	env.AddCell("counter", NewCounterBehaviorFactory(cf))
	env.AddCell("collector", CollectorBehaviorFactory)

	env.Subscribe("counter", "collector")

	env.EmitSimple("counter", "a", true)
	env.EmitSimple("counter", "b", true)
	env.EmitSimple("counter", "c", true)
	env.EmitSimple("counter", "a", true)

	time.Sleep(100 * time.Millisecond)

	b, _ := env.CellBehavior("collector")
	collector := b.(EventCollector)
	events := collector.Events()

	assert.Equal(events[0].Payload().(int64), int64(1), "First result is ok.")
	assert.Equal(events[1].Payload().(int64), int64(1), "Second result is ok.")
	assert.Equal(events[2].Payload().(int64), int64(1), "Third result is ok.")
	assert.Equal(events[3].Payload().(int64), int64(2), "Fourth result is ok.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:30,代碼來源:cells_test.go

示例13: TestFilterBehavior

// TestFilterBehavior tests the filtering of events by the
// filter behavior.
func TestFilterBehavior(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	ff := func(e Event) bool {
		if strings.Contains(e.Topic(), "yes") {
			return true
		}
		return false
	}
	env := NewEnvironment("filter-behavior")
	env.AddCell("filter", NewFilteredBroadcastBehaviorFactory(ff))
	env.AddCell("collector", CollectorBehaviorFactory)

	env.Subscribe("filter", "collector")

	env.EmitSimple("filter", "yes", true)
	env.EmitSimple("filter", "no", true)
	env.EmitSimple("filter", "yes", true)

	time.Sleep(100 * time.Millisecond)

	b, _ := env.CellBehavior("collector")
	collector := b.(EventCollector)
	events := collector.Events()

	assert.Length(events, 2, "All events received")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:29,代碼來源:cells_test.go

示例14: TestUiRPC

func TestUiRPC(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	// Create the UI to test
	ui := new(testUi)

	// Start the RPC server
	server := rpc.NewServer()
	RegisterUi(server, ui)
	address := serveSingleConn(server)

	// Create the client over RPC and run some methods to verify it works
	client, err := rpc.Dial("tcp", address)
	if err != nil {
		panic(err)
	}

	uiClient := &Ui{client}

	// Basic error and say tests
	result, err := uiClient.Ask("query")
	assert.Nil(err, "should not error")
	assert.True(ui.askCalled, "ask should be called")
	assert.Equal(ui.askQuery, "query", "should be correct")
	assert.Equal(result, "foo", "should have correct result")

	uiClient.Error("message")
	assert.Equal(ui.errorMessage, "message", "message should be correct")

	uiClient.Message("message")
	assert.Equal(ui.messageMessage, "message", "message should be correct")

	uiClient.Say("message")
	assert.Equal(ui.sayMessage, "message", "message should be correct")
}
開發者ID:rrudduck,項目名稱:golang-stuff,代碼行數:35,代碼來源:ui_test.go

示例15: TestSimple

// TestSimple tests simple value retrieved as string.
func TestSimple(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	provider := config.NewMapConfigurationProvider()
	cfg := config.New(provider)

	cfg.Set("alpha", "quick brown fox")
	cfg.Set("bravo", true)
	cfg.Set("charlie", 4711)
	cfg.Set("delta", 47.11)

	// Successful gets.
	value, err := cfg.Get("alpha")
	assert.Nil(err, "No error.")
	assert.Equal(value, "quick brown fox", "Right value 'alpha' returned.")
	value, err = cfg.Get("bravo")
	assert.Nil(err, "No error.")
	assert.Equal(value, "true", "Right value 'bravo' returned.")
	value, err = cfg.Get("charlie")
	assert.Nil(err, "No error.")
	assert.Equal(value, "4711", "Right value 'charlie' returned.")
	value, err = cfg.Get("delta")
	assert.Nil(err, "No error.")
	assert.Equal(value, "47.11", "Right value 'delta' returned.")

	// Non-existing key.
	_, err = cfg.Get("non-existing-key")
	assert.ErrorMatch(err, `key "non-existing-key" does not exist`, "Right error returned.")

	// Non-existing key with default.
	value, err = cfg.GetDefault("non-existing-key", "default value")
	assert.Nil(err, "No error.")
	assert.Equal(value, "default value", "Right value 'non-existing-key' returned.")
}
開發者ID:rpeer-denis,項目名稱:tcgl,代碼行數:34,代碼來源:config_test.go


注:本文中的cgl/tideland/biz/asserts.NewTestingAsserts函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。