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


Golang spew.Sdump函数代码示例

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


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

示例1: TestInstanceAdmin

func TestInstanceAdmin(t *testing.T) {
	client, server := test.AdminClient(instanceAdminResponse)
	defer server.Close()
	want :=
		RestartResponse{
			XMLName: xml.Name{Space: "http://marklogic.com/manage", Local: "restart"},
			LastStartup: LastStartupElement{
				XMLName: xml.Name{Space: "http://marklogic.com/manage", Local: "last-startup"},
				Value:   "2013-04-01T10:35:19.09913-07:00",
				HostID:  "13544732455686476949",
			},
			Link: LinkElement{
				XMLName: xml.Name{Space: "http://marklogic.com/manage", Local: "link"},
				KindRef: "timestamp",
				URIRef:  "/admin/v1/timestamp",
			},
			Message: "Check for new timestamp to verify host restart.",
		}
	// Using Basic Auth for test so initial call isn't actually made
	respHandle := RestartResponseHandle{Format: handle.XML}
	err := instanceAdmin(client, "admin", "password", "public", &respHandle)
	resp := respHandle.Get()
	if err != nil {
		t.Errorf("Error = %v", err)
	} else if resp == nil {
		t.Errorf("No response found")
	} else if !reflect.DeepEqual(want.LastStartup, resp.LastStartup) {
		t.Errorf("InstanceAdmin LastStartup = %+v, Want = %+v", spew.Sdump(resp.LastStartup), spew.Sdump(want.LastStartup))
	} else if !reflect.DeepEqual(resp.Link, want.Link) {
		t.Errorf("InstanceAdmin Link = %+v, Want = %+v", spew.Sdump(resp.Link), spew.Sdump(want.Link))
	} else if !reflect.DeepEqual(*resp, want) {
		t.Errorf("InstanceAdmin Response = %+v, Want = %+v", spew.Sdump(*resp), spew.Sdump(want))
	}
}
开发者ID:ryanjdew,项目名称:go-marklogic-go,代码行数:34,代码来源:service_test.go

示例2: testFetchTxBySha

// testFetchTxBySha ensures FetchTxBySha conforms to the interface contract.
func testFetchTxBySha(tc *testContext) bool {
	for i, tx := range tc.block.Transactions() {
		txHash := tx.Sha()
		txReplyList, err := tc.db.FetchTxBySha(txHash)
		if err != nil {
			tc.t.Errorf("FetchTxBySha (%s): block #%d (%s) "+
				"tx #%d (%s) err: %v", tc.dbType, tc.blockHeight,
				tc.blockHash, i, txHash, err)
			return false
		}
		if len(txReplyList) == 0 {
			tc.t.Errorf("FetchTxBySha (%s): block #%d (%s) "+
				"tx #%d (%s) did not return reply data",
				tc.dbType, tc.blockHeight, tc.blockHash, i,
				txHash)
			return false
		}
		txFromDb := txReplyList[len(txReplyList)-1].Tx
		if !reflect.DeepEqual(tx.MsgTx(), txFromDb) {
			tc.t.Errorf("FetchTxBySha (%s): block #%d (%s) "+
				"tx #%d (%s) does not match stored tx\n"+
				"got: %v\nwant: %v", tc.dbType, tc.blockHeight,
				tc.blockHash, i, txHash, spew.Sdump(txFromDb),
				spew.Sdump(tx.MsgTx()))
			return false
		}
	}

	return true
}
开发者ID:rahulxkrishna,项目名称:btcd,代码行数:31,代码来源:interface_test.go

示例3: Equal

// Equal asserts that two objects are equal.
//
//    assert.Equal(t, 123, 123, "123 and 123 should be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {

	if !ObjectsAreEqual(expected, actual) {
		var msg string
		tp := reflect.TypeOf(expected)
		k := tp.Kind()
		if k == reflect.Ptr {
			tp = tp.Elem()
			k = tp.Kind()
		}
		if k == reflect.Struct || k == reflect.Map || k == reflect.Slice || k == reflect.Array {
			msg = fmt.Sprintf("Not equal:\n"+
				"---- Expected ----\n%s\n--------------\n"+
				"---- Actual ------\n%s\n--------------",
				spew.Sdump(expected),
				spew.Sdump(actual))
		} else {
			msg = fmt.Sprintf("Not equal: %#v (expected)\n"+
				"        != %#v (actual)", expected, actual)
		}
		return Fail(t, msg, msgAndArgs...)
	}

	return true

}
开发者ID:2722,项目名称:lantern,代码行数:31,代码来源:assertions.go

示例4: TestSphinxEncodeDecode

func TestSphinxEncodeDecode(t *testing.T) {
	// Create some test data with a randomly populated, yet valid onion
	// forwarding message.
	_, fwdMsg, err := newTestRoute(5)
	if err != nil {
		t.Fatalf("unable to create random onion packet: %v", err)
	}

	// Encode the created onion packet into an empty buffer. This should
	// succeeed without any errors.
	var b bytes.Buffer
	if err := fwdMsg.Encode(&b); err != nil {
		t.Fatalf("unable to encode message: %v", err)
	}

	// Now decode the bytes encoded above. Again, this should succeeed
	// without any errors.
	newFwdMsg := &OnionPacket{}
	if err := newFwdMsg.Decode(&b); err != nil {
		t.Fatalf("unable to decode message: %v", err)
	}

	// The two forwarding messages should now be identical.
	if !reflect.DeepEqual(fwdMsg, newFwdMsg) {
		t.Fatalf("forwarding messages don't match, %v vs %v",
			spew.Sdump(fwdMsg), spew.Sdump(newFwdMsg))
	}
}
开发者ID:lightningnetwork,项目名称:lightning-onion,代码行数:28,代码来源:sphinx_test.go

示例5: TestTestNet3GenesisBlock

// TestTestNet3GenesisBlock tests the genesis block of the test network (version
// 3) for validity by checking the encoded bytes and hashes.
func TestTestNet3GenesisBlock(t *testing.T) {
	// Encode the genesis block to raw bytes.
	var buf bytes.Buffer
	err := btcnet.TestNet3Params.GenesisBlock.Serialize(&buf)
	if err != nil {
		t.Fatalf("TestTestNet3GenesisBlock: %v", err)
	}

	// Ensure the encoded block matches the expected bytes.
	if !bytes.Equal(buf.Bytes(), testNet3GenesisBlockBytes) {
		t.Fatalf("TestTestNet3GenesisBlock: Genesis block does not "+
			"appear valid - got %v, want %v",
			spew.Sdump(buf.Bytes()),
			spew.Sdump(testNet3GenesisBlockBytes))
	}

	// Check hash of the block against expected hash.
	hash, err := btcnet.TestNet3Params.GenesisBlock.BlockSha()
	if err != nil {
		t.Fatalf("BlockSha: %v", err)
	}
	if !btcnet.TestNet3Params.GenesisHash.IsEqual(&hash) {
		t.Fatalf("TestTestNet3GenesisBlock: Genesis block hash does "+
			"not appear valid - got %v, want %v", spew.Sdump(hash),
			spew.Sdump(btcnet.TestNet3Params.GenesisHash))
	}
}
开发者ID:jcvernaleo,项目名称:btcnet,代码行数:29,代码来源:genesis_test.go

示例6: TestWatchNewFile

func TestWatchNewFile(t *testing.T) {
	t.Parallel()

	dir, am := tmpManager(t, false)
	defer os.RemoveAll(dir)

	// Ensure the watcher is started before adding any files.
	am.Accounts()
	time.Sleep(200 * time.Millisecond)

	// Move in the files.
	wantAccounts := make([]Account, len(cachetestAccounts))
	for i := range cachetestAccounts {
		a := cachetestAccounts[i]
		a.File = filepath.Join(dir, filepath.Base(a.File))
		wantAccounts[i] = a
		if err := cp.CopyFile(a.File, cachetestAccounts[i].File); err != nil {
			t.Fatal(err)
		}
	}

	// am should see the accounts.
	var list []Account
	for d := 200 * time.Millisecond; d < 5*time.Second; d *= 2 {
		list = am.Accounts()
		if reflect.DeepEqual(list, wantAccounts) {
			return
		}
		time.Sleep(d)
	}
	t.Errorf("got %s, want %s", spew.Sdump(list), spew.Sdump(wantAccounts))
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:32,代码来源:addrcache_test.go

示例7: diff

// diff returns a diff of both values as long as both are of the same type and
// are a struct, map, slice or array. Otherwise it returns an empty string.
func diff(expected interface{}, actual interface{}) string {
	if expected == nil || actual == nil {
		return ""
	}

	et, ek := typeAndKind(expected)
	at, _ := typeAndKind(actual)

	if et != at {
		return ""
	}

	if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array {
		return ""
	}

	e := spew.Sdump(expected)
	a := spew.Sdump(actual)

	diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
		A:        difflib.SplitLines(e),
		B:        difflib.SplitLines(a),
		FromFile: "Expected",
		FromDate: "",
		ToFile:   "Actual",
		ToDate:   "",
		Context:  1,
	})

	return "\n\nDiff:\n" + diff
}
开发者ID:ClearcodeHQ,项目名称:Go-Forward,代码行数:33,代码来源:assertions.go

示例8: TestFloatCursorIterator_SingleValue

// Ensure a cursor with a single ref value can be converted into an iterator.
func TestFloatCursorIterator_SingleValue(t *testing.T) {
	cur := NewCursor([]CursorItem{
		{Key: 0, Value: float64(100)},
		{Key: 3, Value: float64(200)},
	}, true)

	opt := influxql.IteratorOptions{
		Expr:      &influxql.VarRef{Val: "value"},
		Ascending: true,
		StartTime: influxql.MinTime,
		EndTime:   influxql.MaxTime,
	}
	itr := tsdb.NewFloatCursorIterator("series0", map[string]string{"host": "serverA"}, cur, opt)
	defer itr.Close()

	if p := itr.Next(); !deep.Equal(p, &influxql.FloatPoint{
		Name:  "series0",
		Time:  0,
		Value: float64(100),
	}) {
		t.Fatalf("unexpected point(0): %s", spew.Sdump(p))
	}

	if p := itr.Next(); !deep.Equal(p, &influxql.FloatPoint{
		Name:  "series0",
		Time:  3,
		Value: float64(200),
	}) {
		t.Fatalf("unexpected point(1): %s", spew.Sdump(p))
	}

	if p := itr.Next(); p != nil {
		t.Fatalf("expected eof, got: %s", spew.Sdump(p))
	}
}
开发者ID:skia-dev,项目名称:influxdb,代码行数:36,代码来源:cursor_test.go

示例9: TestFloatCursorIterator_EndTime

// Ensure a cursor iterator does not go past the end time.
func TestFloatCursorIterator_EndTime(t *testing.T) {
	cur := NewCursor([]CursorItem{
		{Key: 0, Value: float64(100)},
		{Key: 3, Value: float64(200)},
		{Key: 4, Value: float64(300)},
	}, true)

	itr := tsdb.NewFloatCursorIterator("x", nil, cur, influxql.IteratorOptions{
		Expr:      &influxql.VarRef{Val: "value"},
		Ascending: true,
		EndTime:   3,
	})
	defer itr.Close()

	// Verify that only two points are emitted.
	if p := itr.Next(); p == nil || p.Time != 0 {
		t.Fatalf("unexpected point(0): %s", spew.Sdump(p))
	}
	if p := itr.Next(); p == nil || p.Time != 3 {
		t.Fatalf("unexpected point(1): %s", spew.Sdump(p))
	}
	if p := itr.Next(); p != nil {
		t.Fatalf("expected eof, got: %s", spew.Sdump(p))
	}
}
开发者ID:skia-dev,项目名称:influxdb,代码行数:26,代码来源:cursor_test.go

示例10: TestAddChild

func TestAddChild(t *testing.T) {
	parent := New()
	children := []Node{
		&Number{
			Value: "1",
		},
		&Number{
			Value: "2",
		},
		&Number{
			Value: "3",
		},
	}
	for _, child := range children {
		parent.AddChild(child)
	}
	if gotChildren := parent.Children(); !reflect.DeepEqual(gotChildren, children) {
		t.Fatalf(
			"Expected: %s\n  but got: %s",
			spew.Sdump(children),
			spew.Sdump(gotChildren),
		)
	}
	for _, child := range children {
		if gotParent := child.Parent(); !reflect.DeepEqual(gotParent, parent) {
			t.Fatalf(
				"Expected: %s\n  but got: %s",
				spew.Sdump(parent),
				spew.Sdump(gotParent),
			)
		}
	}
}
开发者ID:albrow,项目名称:calc,代码行数:33,代码来源:node_test.go

示例11: processOutboundQueue

func (ctxt *snmpContext) processOutboundQueue() {
	defer func() {
		ctxt.outboundDied <- true
		ctxt.conn.Close() // make sure that receive side shuts down too.
	}()
	ctxt.Debugf("Ctxt %s: outbound flow controller initializing", ctxt.name)
	for {
		select {
		case msg := <-ctxt.outboundFlowControlQueue:
			encodedMsg, err := msg.encode(ctxt.berEncoderFactory)
			if err != nil {
				ctxt.Debugf("Couldn't encode message: err: %s. Message:\n%s", err, spew.Sdump(msg))
				continue
			}
			ctxt.Debugf("Ctxt %s: Sending message:\n%s", ctxt.name, spew.Sdump(msg))
			if n, err := ctxt.conn.WriteToUDP(encodedMsg, msg.getAddress()); err != nil || n != len(encodedMsg) {
				if strings.HasSuffix(err.Error(), "closed network connection") {
					ctxt.Debugf("Ctxt %s: outbound flow controller shutting down due to closed connection", ctxt.name)
					ctxt.incrementStat(StatType_OUTBOUND_CONNECTION_CLOSE)
				} else {
					ctxt.Errorf("Ctxt %s: UDP write failed, err: %s, numWritten: %d, expected: %d", ctxt.name, err, n, len(encodedMsg))
					ctxt.incrementStat(StatType_OUTBOUND_CONNECTION_DEATH)
				}
				return
			}
			ctxt.incrementStat(StatType_OUTBOUND_MESSAGES_SENT)
		case <-ctxt.outboundFlowControlShutdown:
			ctxt.Debugf("Ctxt %s: outbound flow controller shutting down due to shutdown message", ctxt.name)
			return
		case <-ctxt.internalShutdownNotification:
			ctxt.Debugf("Ctxt %s: outbound flow controller shutting down due to snmpContext shutdown", ctxt.name)
			return
		}
	}
}
开发者ID:kortschak,项目名称:gosnmp,代码行数:35,代码来源:snmp.go

示例12: TestEmit

func TestEmit(t *testing.T) {
	// Arrange
	e := new(Emitter)
	for i, c := range emitcases {
		if isolateEmitCase >= 0 && isolateEmitCase != i {
			continue
		}
		if testing.Verbose() {
			fmt.Printf("testing emitter case %d...\n", i)
		}

		// Act
		f, err := e.Emit("", c.src, nil)

		// Assert
		if (err != nil) != c.err {
			if err == nil {
				t.Errorf("[%d] - expected an error, got none", i)
			} else {
				t.Errorf("[%d] - expected no error, got `%s`", i, err)
			}
		}
		if c.exp != nil {
			if !equal(i, f, c.exp) {
				t.Errorf("[%d] - expected\n", i)
				t.Error(spew.Sdump(c.exp))
				t.Error("got\n")
				t.Error(spew.Sdump(f))
			}
		}
		if !c.err && c.exp == nil {
			t.Errorf("[%d] - no assertion", i)
		}
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:35,代码来源:emitter_test.go

示例13: TestNone

func TestNone(t *testing.T) {
	ctx := initTest()

	if len(ctx.fd.running()) > 0 {
		t.Errorf("fd.running = %s; want <empty>", spew.Sdump(ctx.fd.running()))
	}

	if len(ctx.execs) > 0 {
		t.Errorf("exec = %s; want <empty>", spew.Sdump(ctx.execs))
	}

	ctx.conn.Transact(func(view db.Database) error {
		m, _ := view.MinionSelf()
		e := view.SelectFromEtcd(nil)[0]
		m.PrivateIP = "1.2.3.4"
		e.Leader = false
		e.LeaderIP = "5.6.7.8"
		view.Commit(m)
		view.Commit(e)
		return nil
	})
	ctx.run()

	if len(ctx.fd.running()) > 0 {
		t.Errorf("fd.running = %s; want <none>", spew.Sdump(ctx.fd.running()))
	}

	if len(ctx.execs) > 0 {
		t.Errorf("exec = %s; want <empty>", spew.Sdump(ctx.execs))
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:31,代码来源:supervisor_test.go

示例14: writeMessage

// writeMessage sends a bitcoin Message to the peer with logging.
func (p *peer) writeMessage(msg btcwire.Message) {
	// Don't do anything if we're disconnecting.
	if atomic.LoadInt32(&p.disconnect) != 0 {
		return
	}

	log.Debugf("[PEER] Sending command [%v] to %s", msg.Command(),
		p.addr)

	// Use closures to log expensive operations so they are only run when the
	// logging level requires it.
	log.Tracef("%v", newLogClosure(func() string {
		return "[PEER] msg" + spew.Sdump(msg)
	}))
	log.Tracef("%v", newLogClosure(func() string {
		var buf bytes.Buffer
		err := btcwire.WriteMessage(&buf, msg, p.protocolVersion, p.btcnet)
		if err != nil {
			return err.Error()
		}
		return "[PEER] " + spew.Sdump(buf.Bytes())
	}))

	// Write the message to the peer.
	err := btcwire.WriteMessage(p.conn, msg, p.protocolVersion, p.btcnet)
	if err != nil {
		p.Disconnect()
		p.logError("[PEER] Can't send message: %v", err)
		return
	}
}
开发者ID:kazcw,项目名称:btcd,代码行数:32,代码来源:peer.go

示例15: checkJavascript

func checkJavascript(t *testing.T, code string, exp interface{}) {
	resultKey := "result"

	vm, err := newVM(ImportGetter{
		Path: ".",
	})
	if err != nil {
		t.Errorf(`Unexpected error: "%s".`, err.Error())
		return
	}

	exec := fmt.Sprintf(`exports.%s = %s;`, resultKey, code)
	moduleVal, err := runSpec(vm, "<test_code>", exec)
	if err != nil {
		t.Errorf(`Unexpected error: "%s".`, err.Error())
		return
	}

	actualVal, err := moduleVal.Object().Get(resultKey)
	if err != nil {
		t.Errorf(`Unexpected error retrieving result from VM: "%s".`,
			err.Error())
		return
	}

	actual, _ := actualVal.Export()
	if !reflect.DeepEqual(actual, exp) {
		t.Errorf("Bad javascript code: Expected %s, got %s.",
			spew.Sdump(exp), spew.Sdump(actual))
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:31,代码来源:stitch_test.go


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