本文整理汇总了Golang中github.com/davecgh/go-spew/spew.Sprintf函数的典型用法代码示例。如果您正苦于以下问题:Golang Sprintf函数的具体用法?Golang Sprintf怎么用?Golang Sprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sprintf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestHashJoinNilKeyFunc
func TestHashJoinNilKeyFunc(t *testing.T) {
keyFunc := func(val interface{}) interface{} {
return val
}
pairs, left, right := HashJoin(JoinList{10, 11, 12},
JoinList{10, 11, 12}, nil, keyFunc)
if len(left) > 0 {
t.Errorf("Unexpected lefts: %s", left)
}
if len(right) > 0 {
t.Errorf("Unexpected rights: %s", right)
}
if !eq(pairs, []Pair{{10, 10}, {11, 11}, {12, 12}}) {
t.Error(spew.Sprintf("Unexpected pairs: %s", pairs))
}
pairs, left, right = HashJoin(JoinList{10, 11, 12},
JoinList{13, 11, 2}, keyFunc, nil)
if len(left) != 2 {
t.Error(spew.Sprintf("Unexpected left: %s", left))
}
if len(right) != 2 {
t.Error(spew.Sprintf("Unexpected right %s", right))
}
if !eq(pairs, []Pair{{11, 11}}) {
t.Error(spew.Sprintf("Unexpected pairs: %s", pairs))
}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:28,代码来源:join_test.go
示例2: TestJoin
func TestJoin(t *testing.T) {
score := func(left, right interface{}) int {
return left.(int) - right.(int)
}
pairs, left, right := Join([]int{10, 11, 12}, []int{10, 11, 12}, score)
if len(left) > 0 {
t.Errorf("Unexpected lefts: %s", left)
}
if len(right) > 0 {
t.Errorf("Unexpected rights: %s", right)
}
if !eq(pairs, []Pair{{10, 10}, {11, 11}, {12, 12}}) {
t.Error(spew.Sprintf("Unexpected pairs: %s", pairs))
}
pairs, left, right = Join([]int{10, 11, 12}, []int{13, 1, 2}, score)
if !eq(left, []interface{}{12}) {
t.Error(spew.Sprintf("Unexpected left: %s", left))
}
if !eq(right, []interface{}{13}) {
t.Error(spew.Sprintf("Unexpected right %s", right))
}
if !eq(pairs, []Pair{{10, 2}, {11, 1}}) {
t.Error(spew.Sprintf("Unexpected pairs: %s", pairs))
}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:27,代码来源:join_test.go
示例3: valueTest
func valueTest(actual, expected interface{}) {
if expected == nil {
Convey(`... should create no value.`, func() {
So(actual, ShouldBeNil)
})
} else {
Convey(`... should create the right value.`, func() {
So(fmt.Sprintf("%T", actual), ShouldEqual, fmt.Sprintf("%T", expected))
So(spew.Sprintf("%v", actual), ShouldEqual, spew.Sprintf("%v", expected))
})
}
}
开发者ID:flowdev,项目名称:gflowparser,代码行数:12,代码来源:parseUtils_test.go
示例4: TestGetDirectory
func TestGetDirectory(t *testing.T) {
store := NewMock()
paths := []string{
"/a/b",
"/a/c/d/e",
}
for _, p := range paths {
if err := store.Set(p, p); err != nil {
t.Fatal(err)
}
}
dir, err := getDirectory(store, "/")
if err != nil {
t.Fatal(err)
}
exp := make(directory)
exp["a"] = map[string]string{"b": "/a/b", "c": ""}
if !eq(dir, exp) {
t.Error(spew.Sprintf("\nGet Directory:\n%s\n\nExpected:\n%s\n", dir, exp))
}
dir, err = getDirectory(store, "/a")
if err != nil {
t.Fatal(err)
}
exp = make(directory)
exp["b"] = map[string]string{}
exp["c"] = map[string]string{"d": ""}
if !eq(dir, exp) {
t.Error(spew.Sprintf("\nGet Directory:\n%s\n\nExpected:\n%s\n", dir, exp))
}
dir, err = getDirectory(store, "/a/c")
if err != nil {
t.Fatal(err)
}
exp = make(directory)
exp["d"] = map[string]string{"e": "/a/c/d/e"}
if !eq(dir, exp) {
t.Error(spew.Sprintf("\nGetDirectory:\n%s\n\nExpected:\n%s\n", dir, exp))
}
if val, err := getDirectory(store, "/junk"); err == nil {
t.Error(spew.Sprintf("Expected error, got %s", val))
}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:52,代码来源:network_test.go
示例5: Error
func (v *ValidationError) Error() string {
var s string
switch v.Type {
case ValidationErrorTypeRequired:
s = spew.Sprintf("%s: %s", v.Field, v.Type)
default:
s = spew.Sprintf("%s: %s '%+v'", v.Field, v.Type, v.BadValue)
}
if len(v.Detail) != 0 {
s += fmt.Sprintf(": %s", v.Detail)
}
return s
}
开发者ID:brorhie,项目名称:panamax-kubernetes-adapter-go,代码行数:13,代码来源:validation.go
示例6: ErrorBody
// ErrorBody returns the error message without the field name. This is useful
// for building nice-looking higher-level error reporting.
func (v *Error) ErrorBody() string {
var s string
switch v.Type {
case ErrorTypeRequired, ErrorTypeTooLong, ErrorTypeInternal:
s = spew.Sprintf("%s", v.Type)
default:
s = spew.Sprintf("%s '%+v'", v.Type, v.BadValue)
}
if len(v.Detail) != 0 {
s += fmt.Sprintf(", Details: %s", v.Detail)
}
return s
}
开发者ID:erinboyd,项目名称:origin,代码行数:15,代码来源:errors.go
示例7: TestSyncDB
func TestSyncDB(t *testing.T) {
spew := spew.NewDefaultConfig()
spew.MaxDepth = 2
checkSyncDB := func(cloudMachines []provider.Machine,
databaseMachines []db.Machine, expectedBoot,
expectedStop []provider.Machine) {
_, bootResult, stopResult := syncDB(cloudMachines, databaseMachines)
if !emptySlices(bootResult, expectedBoot) &&
!reflect.DeepEqual(bootResult, expectedBoot) {
t.Error(spew.Sprintf(
"booted wrong machines. Expected %v, got %v.",
expectedBoot, bootResult))
}
if !emptySlices(stopResult, expectedStop) && !reflect.DeepEqual(
stopResult, expectedStop) {
t.Error(spew.Sprintf(
"stopped wrong machines. Expected %v, got %v.",
expectedStop, stopResult))
}
}
var noMachines []provider.Machine
dbNoSize := db.Machine{Provider: FakeAmazon}
cmNoSize := provider.Machine{Provider: FakeAmazon}
dbLarge := db.Machine{Provider: FakeAmazon, Size: "m4.large"}
cmLarge := provider.Machine{Provider: FakeAmazon, Size: "m4.large"}
// Test boot with no size
checkSyncDB(noMachines, []db.Machine{dbNoSize}, []provider.Machine{cmNoSize},
noMachines)
// Test boot with size
checkSyncDB(noMachines, []db.Machine{dbLarge}, []provider.Machine{cmLarge},
noMachines)
// Test mixed boot
checkSyncDB(noMachines, []db.Machine{dbNoSize, dbLarge}, []provider.Machine{
cmNoSize, cmLarge}, noMachines)
// Test partial boot
checkSyncDB([]provider.Machine{cmNoSize}, []db.Machine{dbNoSize, dbLarge},
[]provider.Machine{cmLarge}, noMachines)
// Test stop
checkSyncDB([]provider.Machine{cmNoSize}, []db.Machine{}, noMachines,
[]provider.Machine{cmNoSize})
// Test partial stop
checkSyncDB([]provider.Machine{cmNoSize, cmLarge}, []db.Machine{}, noMachines,
[]provider.Machine{cmNoSize, cmLarge})
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:51,代码来源:cluster_test.go
示例8: TestInto
func TestInto(t *testing.T) {
cache, err := cachei.Open("redis", cachei.DataSource{})
if err != nil {
t.Fatal(err)
}
for i, tt := range cacheTests {
cacheMiss := false
missFunc := func() (interface{}, error) {
cacheMiss = true
return tt.value, nil
}
verr, cerr := cache.OutSetFn(fmt.Sprintf("__kdarcacheinto_redis_test_%d", i), 1, tt.into, missFunc)
if verr != nil {
t.Fatal(verr)
}
if cerr != nil {
t.Fatal(cerr)
}
if !cacheMiss {
t.Fatalf("%d-1. Expected a cache miss, but instead found cache", i)
}
if !reflect.DeepEqual(tt.value, reflect.ValueOf(tt.into).Elem().Interface()) {
t.Fatalf("%d-1. Expected:\n%s,\ngot:\n%s", i, spew.Sprintf("%#v", &tt.value), spew.Sprintf("%#v", tt.into))
}
cacheMiss = false
verr, cerr = cache.OutSetFn(fmt.Sprintf("__kdarcacheinto_redis_test_%d", i), 1, tt.into, missFunc)
if verr != nil {
t.Fatal(verr)
}
if cerr != nil {
t.Fatal(cerr)
}
if cacheMiss {
t.Fatalf("%d-2. Expected cache, but instead got a cache miss.", i)
}
if !reflect.DeepEqual(tt.value, reflect.ValueOf(tt.into).Elem().Interface()) {
t.Fatalf("%d-2. Expected: %s, got: %s", i, spew.Sprintf("%#v", tt.value), spew.Sprintf("%#v", tt.into))
}
}
}
开发者ID:kdar,项目名称:cachei,代码行数:51,代码来源:redis_test.go
示例9: testReadContainerTransact
func testReadContainerTransact(t *testing.T, view db.Database) {
minion := view.InsertMinion()
minion.Role = db.Worker
minion.Self = true
view.Commit(minion)
for _, id := range []string{"a", "b"} {
container := view.InsertContainer()
container.DockerID = id
view.Commit(container)
}
container := view.InsertContainer()
container.DockerID = "c"
container.IP = "junk"
view.Commit(container)
dir := directory(map[string]map[string]string{
"a": {"IP": "1.0.0.0", "Labels": `["e"]`},
"b": {"IP": "2.0.0.0", "Labels": `["e", "f"]`},
})
readContainerTransact(view, dir)
ipMap := map[string]string{}
labelMap := map[string][]string{}
for _, c := range view.SelectFromContainer(nil) {
ipMap[c.DockerID] = c.IP
labelMap[c.DockerID] = c.Labels
}
expIPMap := map[string]string{
"a": "1.0.0.0",
"b": "2.0.0.0",
"c": "",
}
if !eq(ipMap, expIPMap) {
t.Error(spew.Sprintf("Found %s, Expected: %s", ipMap, expIPMap))
}
expLabelMap := map[string][]string{
"a": {"e"},
"b": {"e", "f"},
"c": nil,
}
if !eq(labelMap, expLabelMap) {
t.Error(spew.Sprintf("Found %s, Expected: %s", ipMap, expIPMap))
}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:50,代码来源:network_test.go
示例10: TestGet
func TestGet(t *testing.T) {
cache, err := cachei.Open("redis", cachei.DataSource{})
if err != nil {
t.Fatal(err)
}
for i, tt := range cacheTests {
cacheMiss := false
missFunc := func() (interface{}, error) {
cacheMiss = true
return tt.value, nil
}
v1, verr, cerr := cache.GetSetFn(fmt.Sprintf("__kdarcacheget_redis_test_%d", i), 1, missFunc)
if verr != nil {
t.Fatal(verr)
}
if cerr != nil {
t.Fatal(cerr)
}
if !cacheMiss {
t.Fatalf("%d-1. Expected a cache miss, but instead found cache", i)
}
if !reflect.DeepEqual(tt.value, v1) {
t.Fatalf("%d-1. Expected: %s, got: %s", i, spew.Sprintf("%#v", tt.value), spew.Sprintf("%#v", v1))
}
cacheMiss = false
v2, verr, cerr := cache.GetSetFn(fmt.Sprintf("__kdarcacheget_redis_test_%d", i), 1, missFunc)
if verr != nil {
t.Fatal(verr)
}
if cerr != nil {
t.Fatal(cerr)
}
if cacheMiss {
t.Fatalf("%d-2. Expected cache, but instead got a cache miss.", i)
}
if !reflect.DeepEqual(v1, v2) {
t.Fatalf("%d-2. Expected: %s, got: %s", i, spew.Sprintf("%#v", v1), spew.Sprintf("%#v", v2))
}
}
}
开发者ID:kdar,项目名称:cachei,代码行数:50,代码来源:redis_test.go
示例11: TestSyncLabels
func TestSyncLabels(t *testing.T) {
store := NewMock()
store.Mkdir("/test/a")
store.Mkdir("/test/b")
store.Mkdir("/test/c")
dir, _ := getDirectory(store, "/test")
containers := []db.Container{
{DockerID: "a", Labels: []string{"d", "c"}},
{DockerID: "b", Labels: []string{}},
{DockerID: "c", Labels: nil},
}
syncLabels(store, dir, "/test", containers)
newDir, _ := getDirectory(store, "/test")
if !eq(dir, newDir) {
t.Error(spew.Sprintf("syncLabels did not update dir.\n"+
"Found %s\nExpected %s", dir, newDir))
}
expDir := directory(map[string]map[string]string{
"a": {"Labels": `["c","d"]`},
"b": {"Labels": "[]"},
"c": {"Labels": "[]"},
})
if !eq(dir, expDir) {
t.Error(spew.Sprintf("syncLabels Found %s\nExpected %s", dir, expDir))
}
containers = []db.Container{
{DockerID: "a", Labels: []string{"d", "c"}},
}
syncLabels(store, dir, "/test", containers)
newDir, _ = getDirectory(store, "/test")
if !eq(dir, newDir) {
t.Error(spew.Sprintf("syncLabels did not update dir.\n"+
"Found %s\nExpected %s", dir, newDir))
}
expDir = directory(map[string]map[string]string{
"a": {"Labels": `["c","d"]`},
"b": {"Labels": `[]`},
"c": {"Labels": `[]`},
})
if !eq(dir, expDir) {
t.Error(spew.Sprintf("syncLabels Found %s\nExpected %s", dir, expDir))
}
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:49,代码来源:network_test.go
示例12: newVolumeBuilderFromPlugins
func (kl *Kubelet) newVolumeBuilderFromPlugins(spec *api.Volume, podRef *api.ObjectReference) (volume.Builder, error) {
plugin, err := kl.volumePluginMgr.FindPluginBySpec(spec)
if err != nil {
return nil, fmt.Errorf("can't use volume plugins for %s: %v", spew.Sprintf("%#v", *spec), err)
}
if plugin == nil {
// Not found but not an error
return nil, nil
}
builder, err := plugin.NewBuilder(spec, podRef)
if err != nil {
return nil, fmt.Errorf("failed to instantiate volume plugin for %s: %v", spew.Sprintf("%#v", *spec), err)
}
glog.V(3).Infof("Used volume plugin %q for %s", plugin.Name(), spew.Sprintf("%#v", *spec))
return builder, nil
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:16,代码来源:volumes.go
示例13: TestKeys
func TestKeys(t *testing.T) {
getGithubKeys = func(username string) ([]string, error) {
return []string{username}, nil
}
checkKeys := func(code, expectedCode string, expected ...string) {
ctx := parseTest(t, code, expectedCode)
machineResult := Stitch{"", ctx}.QueryMachines()
if len(machineResult) == 0 {
t.Error("no machine found")
return
}
if !reflect.DeepEqual(machineResult[0].SSHKeys, expected) {
t.Error(spew.Sprintf("test: %s, result: %s, expected: %s",
code, machineResult[0].SSHKeys, expected))
}
}
code := `(machine (sshkey "key"))`
checkKeys(code, code, "key")
code = `(machine (githubKey "user"))`
checkKeys(code, code, "user")
code = `(machine (githubKey "user") (sshkey "key"))`
checkKeys(code, code, "user", "key")
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:27,代码来源:stitch_test.go
示例14: newVolumeBuilderFromPlugins
func (kl *Qinglet) newVolumeBuilderFromPlugins(spec *volume.Spec, pod *api.Pod, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
plugin, err := kl.volumePluginMgr.FindPluginBySpec(spec)
if err != nil {
return nil, fmt.Errorf("can't use volume plugins for %s: %v", spew.Sprintf("%#v", *spec), err)
}
if plugin == nil {
// Not found but not an error
return nil, nil
}
builder, err := plugin.NewBuilder(spec, pod, opts, mounter)
if err != nil {
return nil, fmt.Errorf("failed to instantiate volume plugin for %s: %v", spew.Sprintf("%#v", *spec), err)
}
glog.V(3).Infof("Used volume plugin %q for %s", plugin.Name(), spew.Sprintf("%#v", *spec))
return builder, nil
}
开发者ID:qingyuancloud,项目名称:qingyuan,代码行数:16,代码来源:volumes.go
示例15: dump
// ES: Yes, it isn't great. Whatever. Go fix something else.
func dump(obj interface{}) string {
x, err := json.Marshal(obj)
if err != nil {
return spew.Sprintf("%+v", obj)
}
return string(x)
}
开发者ID:ninjasphere,项目名称:driver-go-hue,代码行数:8,代码来源:driver.go
示例16: Write
func (m *MessageAggregator) Write(envelope *events.Envelope) {
// TODO: don't call for every message if throughput becomes a problem
m.cleanupOrphanedHTTPStart()
if envelope.EventType == nil {
m.outputWriter.Write(envelope)
return
}
switch envelope.GetEventType() {
case events.Envelope_HttpStart:
m.handleHTTPStart(envelope)
case events.Envelope_HttpStop:
startStopMessage := m.handleHTTPStop(envelope)
if startStopMessage != nil {
m.outputWriter.Write(startStopMessage)
}
case events.Envelope_CounterEvent:
counterEventMessage := m.handleCounter(envelope)
m.outputWriter.Write(counterEventMessage)
default:
m.incrementCounter(&m.uncategorizedEventCount)
m.logger.Debugf("passing through message %v", spew.Sprintf("%v", envelope))
m.outputWriter.Write(envelope)
}
}
开发者ID:khj0651,项目名称:loggregator,代码行数:25,代码来源:message_aggregator.go
示例17: TestInvalidBST
func TestInvalidBST(t *testing.T) {
tree := Node(1, Leaf(2), Leaf(3))
if tree.IsBST() {
t.Error(spew.Sprintf("%v should not be a bst", tree))
}
}
开发者ID:devmop,项目名称:interviews,代码行数:7,代码来源:bst_test.go
示例18: Error
func (v *ValidationError) Error() string {
s := spew.Sprintf("%s: %s '%+v'", v.Field, v.Type, v.BadValue)
if v.Detail != "" {
s += fmt.Sprintf(": %s", v.Detail)
}
return s
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:7,代码来源:validation.go
示例19: TestDeserializeLines
func TestDeserializeLines(t *testing.T) {
config.produce.partitioner = "hashCode"
data := []struct {
in string
literal bool
partition int32
partitionCount int32
expected message
}{
{
in: "",
literal: false,
partitionCount: 1,
expected: newMessage("", "", 0),
},
{
in: `{"key":"hans","value":"123"}`,
literal: false,
partitionCount: 4,
expected: newMessage("hans", "123", hashCodePartition("hans", 4)),
},
{
in: `{"key":"hans","value":"123","partition":1}`,
literal: false,
partitionCount: 3,
expected: newMessage("hans", "123", 1),
},
{
in: `{"other":"json","values":"avail"}`,
literal: true,
partition: 2,
partitionCount: 4,
expected: newMessage("", `{"other":"json","values":"avail"}`, 2),
},
{
in: `so lange schon`,
literal: false,
partitionCount: 3,
expected: newMessage("", "so lange schon", 0),
},
}
for _, d := range data {
in := make(chan string, 1)
out := make(chan message)
config.produce.literal = d.literal
config.produce.partition = d.partition
go deserializeLines(in, out, d.partitionCount)
in <- d.in
select {
case <-time.After(50 * time.Millisecond):
t.Errorf("did not receive output in time")
case actual := <-out:
if !(reflect.DeepEqual(d.expected, actual)) {
t.Errorf(spew.Sprintf("\nexpected %#v\nactual %#v", d.expected, actual))
}
}
}
}
开发者ID:fgeller,项目名称:kt,代码行数:60,代码来源:produce_test.go
示例20: TestValidBST
func TestValidBST(t *testing.T) {
for _, tree := range valid {
if !tree.IsBST() {
t.Error(spew.Sprintf("%v should be a bst", tree))
}
}
}
开发者ID:devmop,项目名称:interviews,代码行数:8,代码来源:bst_test.go
注:本文中的github.com/davecgh/go-spew/spew.Sprintf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论