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


Golang convey.Convey函数代码示例

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


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

示例1: TestCapnpWillCompileOurOutput

func TestCapnpWillCompileOurOutput(t *testing.T) {

	cv.Convey("Given a parsable golang source file with a simple struct", t, func() {
		cv.Convey("then when we generate capnp code, it should compile", func() {

			in1 := `
type in1 struct {
	Str string
	N   int
    D   float64
}`

			s1, err := ExtractFromString(in1)
			if err != nil {
				panic(err)
			}

			//expect1 := `struct In1 { str @0: Text; n @1: Int64; d @2: Float64; } `
			//cv.So(string(s1), cv.ShouldEqual, expect1)

			// no news on compile is good news
			_, err, x := CapnpCompileFragment(s1)
			cv.So(err, cv.ShouldEqual, nil)

			x.Cleanup()
		})
	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:28,代码来源:compile_test.go

示例2: TestReplicaJob

func TestReplicaJob(t *testing.T) {

	cv.Convey("If we start a job with a replication factor of 2", t, func() {
		cv.Convey("then the first job to finish should notify and cancel the other workers on that job", func() {
		})
	})
}
开发者ID:robmurtha,项目名称:goq,代码行数:7,代码来源:replicajob_test.go

示例3: TestEnvCannotContainKey

func TestEnvCannotContainKey(t *testing.T) {
	cv.Convey("To avoid transmitting the clusterid, the Env sent to the shepard/worker cannot contain COG_ variables or the clusterid", t, func() {
		cv.Convey("The 8 GOQ env var should all be subtracted by GetNonGOQEnv(), as well as any variable that has the specified cid in it", func() {

			// *** universal test cfg setup
			skipbye := false
			cfg := NewTestConfig()
			defer cfg.ByeTestConfig(&skipbye)
			// *** end universal test setup

			e := make(map[string]string)
			cfg.InjectConfigIntoMap(&e)

			e["UNTOUCHED"] = "sane"
			randomCid := RandomClusterId()
			e["SHALLNOTPASS"] = randomCid

			env2 := MapToEnv(e)

			cv.So(len(env2), cv.ShouldEqual, 11) // the 8 from cfg + UNTOUCHED and SHALLNOTPASS
			res := GetNonGOQEnv(env2, randomCid)

			cv.So(len(res), cv.ShouldEqual, 1)
			cv.So(res[0], cv.ShouldEqual, "UNTOUCHED=sane")
		})
	})
}
开发者ID:robmurtha,项目名称:goq,代码行数:27,代码来源:cfgenv_test.go

示例4: TestSubmitShutdownToLocalJobServ

func TestSubmitShutdownToLocalJobServ(t *testing.T) {

	cv.Convey("with a local jobserv, we should be able to submit a shutdown job to the server", t, func() {
		cv.Convey("and then server go routine should shut itself down cleanly", func() {

			// *** universal test cfg setup
			skipbye := false
			cfg := NewTestConfig()
			defer cfg.ByeTestConfig(&skipbye)
			// *** end universal test setup

			cfg.JservIP = ""
			jobserv, err := NewJobServ(cfg)
			if err != nil {
				panic(err)
			}
			defer CleanupOutdir(cfg)

			sub, err := NewLocalSubmitter(jobserv)
			if err != nil {
				panic(err)
			}
			sub.SubmitShutdownJob()

			<-jobserv.Done
			// we should get past the receive on Done when jobserv closes down:
			cv.So(true, cv.ShouldEqual, true)

		})
	})
}
开发者ID:robmurtha,项目名称:goq,代码行数:31,代码来源:fetch_test.go

示例5: TestTextAndTextListContaintingStruct

func TestTextAndTextListContaintingStruct(t *testing.T) {

	zjobBytes := CapnpEncode(`(cmd = "abc", args = ["xyz"])`, "Zjob")

	cv.Convey("Given a simple struct message Zjob containing a string (cmd='abc') and a list of string (args=['xyz'])", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {

			seg := capn.NewBuffer(nil)
			zjob := air.NewRootZjob(seg)
			zjob.SetCmd("abc")
			tl := seg.NewTextList(1)
			tl.Set(0, "xyz")
			zjob.SetArgs(tl)

			buf := bytes.Buffer{}
			seg.WriteTo(&buf)

			act := buf.Bytes()
			fmt.Printf("          actual:\n")
			ShowBytes(act, 10)

			fmt.Printf("expected:\n")
			ShowBytes(zjobBytes, 10)

			cv.So(act, cv.ShouldResemble, zjobBytes)
		})
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:28,代码来源:struct_test.go

示例6: Test004SingleSlice

func Test004SingleSlice(t *testing.T) {

	cv.Convey("Given a parsable golang source file with type Vector struct { M []int }", t, func() {
		cv.Convey("then we should generate translation utility methods for List(Int64) <-> []int in the capnp output", func() {

			ex0 := `
type Vector struct {
  M []int
}`
			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `

func Int64ListToSliceInt(p capn.Int64List) []int {
	v := make([]int, p.Len())
	for i := range v {
		v[i] = int(p.At(i))
	}
	return v
}
`)

			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `
func SliceIntToInt64List(seg *capn.Segment, m []int) capn.Int64List {
	lst := seg.NewInt64List(len(m))
	for i := range m {
		lst.Set(i, int64(m[i]))
	}
	return lst
}

`)
		})
	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:33,代码来源:singleslice_test.go

示例7: TestBitList

func TestBitList(t *testing.T) {
	seg, _ := zboolvec_value_FilledSegment(5, 3)
	text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "Z")

	expectedText := `(boolvec = [true, false, true])`

	cv.Convey("Given a go-capnproto created List(Bool) Z::boolvec with bool values [true, false, true]", t, func() {
		cv.Convey("When we decode it with capnp", func() {
			cv.Convey(fmt.Sprintf("Then we should get the expected text '%s'", expectedText), func() {
				cv.So(text, cv.ShouldEqual, expectedText)
			})
			cv.Convey("And our data should contain Z_BOOLVEC with contents true, false, true", func() {
				z := air.ReadRootZ(seg)
				cv.So(z.Which(), cv.ShouldEqual, air.Z_BOOLVEC)

				var bitlist = z.Boolvec()
				cv.So(bitlist.Len(), cv.ShouldEqual, 3)
				cv.So(bitlist.At(0), cv.ShouldEqual, true)
				cv.So(bitlist.At(1), cv.ShouldEqual, false)
				cv.So(bitlist.At(2), cv.ShouldEqual, true)
			})
		})
	})

}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:25,代码来源:boollist_test.go

示例8: Test017WriteRead_StructPointerWithinStruct

func Test017WriteRead_StructPointerWithinStruct(t *testing.T) {

	tdir := NewTempDir()
	// comment the defer out to debug any rw test failures.
	defer tdir.Cleanup()

	err := exec.Command("cp", "rw3.go.txt", tdir.DirPath+"/rw3.go").Run()
	if err != nil {
		panic(err)
	}

	MainArgs([]string{os.Args[0], "-o", tdir.DirPath, "rw3.go.txt"})

	cv.Convey("Given bambam generated go bindings: with a struct pointer within a struct", t, func() {
		cv.Convey("then we should be able to write to disk, and read back the same structure", func() {
			cv.So(err, cv.ShouldEqual, nil)

			tdir.MoveTo()

			err = exec.Command("capnpc", "-ogo", "schema.capnp").Run()
			cv.So(err, cv.ShouldEqual, nil)

			err = exec.Command("go", "build").Run()
			cv.So(err, cv.ShouldEqual, nil)

			// run it
			err = exec.Command("./" + tdir.DirPath).Run()
			cv.So(err, cv.ShouldEqual, nil)

		})
	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:32,代码来源:rw3_test.go

示例9: TestDecodeOnKnownWellPackedData

func TestDecodeOnKnownWellPackedData(t *testing.T) {

	// length 17
	byteSliceIn := []byte{0x10, 0x5, 0x50, 0x2, 0x1, 0x1, 0x25, 0x0, 0x0, 0x11, 0x1, 0xc, 0xf, 0xd4, 0x7, 0xc, 0x7}
	fmt.Printf("len of byteSliceIn is %d\n", len(byteSliceIn))
	// annotated: byteSliceIn := []byte{tag:0x10, 0x5, tag:0x50, 0x2, 0x1, tag:0x1, 0x25, tag:0x0, 0x0, tag:0x11, 0x1, 0xc, tag:0xf, 0xd4, 0x7, 0xc, 0x7}

	// length 48
	expectedOut := []byte{0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0xd4, 0x7, 0xc, 0x7, 0x0, 0x0, 0x0, 0x0}

	r := bytes.NewReader(byteSliceIn)
	actual, err := ioutil.ReadAll(capn.NewDecompressor(r))
	if err != nil {
		panic(err)
	}

	cv.Convey("Given a known-to-be-correctly packed 17-byte long sequence for a ZdateVector holding a single Zdate", t, func() {
		cv.Convey("When we use go-capnproto NewDecompressor", func() {
			cv.Convey("Then we should get the same unpacked bytes as capnp provides", func() {
				cv.So(len(actual), cv.ShouldResemble, len(expectedOut))
				cv.So(actual, cv.ShouldResemble, expectedOut)
			})
		})
	})

}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:26,代码来源:stream_test.go

示例10: TestCreationOfZData

func TestCreationOfZData(t *testing.T) {
	const n = 20
	seg, _ := zdataFilledSegment(n)
	text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "Z")

	expectedText := `(zdata = (data = "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13"))`

	cv.Convey("Given a go-capnproto created Zdata DATA element with n=20", t, func() {
		cv.Convey("When we decode it with capnp", func() {
			cv.Convey(fmt.Sprintf("Then we should get the expected text '%s'", expectedText), func() {
				cv.So(text, cv.ShouldEqual, expectedText)
			})
			cv.Convey("And our data should contain Z_ZDATA with contents 0,1,2,...,n", func() {
				z := air.ReadRootZ(seg)
				cv.So(z.Which(), cv.ShouldEqual, air.Z_ZDATA)

				var data []byte = z.Zdata().Data()
				cv.So(len(data), cv.ShouldEqual, n)
				for i := range data {
					cv.So(data[i], cv.ShouldEqual, i)
				}

			})
		})
	})

}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:27,代码来源:create_test.go

示例11: TestWebGoesUpAndDown

func TestWebGoesUpAndDown(t *testing.T) {

	// *** universal test cfg setup
	skipbye := false
	cfg := NewTestConfig() // bumps cfg.TestportBump so cfg.GetWebPort() is different in test.
	defer cfg.ByeTestConfig(&skipbye)
	// *** end universal test setup

	s := NewWebServer()
	cv.Convey("NewWebServer() should bring up a debug web-server", t, func() {
		cv.So(PortIsBound(s.Addr), cv.ShouldEqual, true)
		by, err := FetchUrl("http://" + s.Addr + "/debug/pprof")
		cv.So(err, cv.ShouldEqual, nil)
		//fmt.Printf("by:'%s'\n", string(by))
		cv.So(strings.HasPrefix(string(by), `<html>
<head>
<title>/debug/pprof/</title>
</head>
/debug/pprof/<br>
<br>`), cv.ShouldEqual, true)

	})

	cv.Convey("WebServer::Stop() should bring down the debug web-server", t, func() {
		s.Stop()
		cv.So(PortIsBound(s.Addr), cv.ShouldEqual, false)
	})
}
开发者ID:robmurtha,项目名称:goq,代码行数:28,代码来源:web_test.go

示例12: TestDiffB

func TestDiffB(t *testing.T) {

	cv.Convey("Given two different (possibly long, differing in whitespace) strings a and b", t, func() {
		cv.Convey("then DiffB(a, b) should return the output of diff -b to consisely summarize their differences", func() {

			a := `
1
2
3
4
5
type   s1    struct {
  MyInts    []int
}`
			b := `
1
2
3
4
type s1 struct {
  MyInts []int
}`
			cv.So(string(Diffb(a, b)), cv.ShouldEqual, `6d5
< 5
`)

		})
	})
}
开发者ID:robmurtha,项目名称:bambam,代码行数:29,代码来源:diff_test.go

示例13: Test002ListListStructList

func Test002ListListStructList(t *testing.T) {

	cv.Convey("Given type RWTest struct { NestMatrix [][]Nester1; } in go, where Nester1 is a struct, and a mirror/parallel capnp struct air.RWTestCapn { nestMatrix @0: List(List(Nester1Capn)); } defined in the aircraftlib schema", t, func() {
		cv.Convey("When we Save() RWTest to capn and then Load() it back, the data should match, so that we have working List(List(Struct)) serialization and deserializatoin in go-capnproto", func() {

			// full RWTest
			rw := RWTest{
				NestMatrix: [][]Nester1{[]Nester1{Nester1{Strs: []string{"z", "w"}}, Nester1{Strs: []string{"q", "r"}}}, []Nester1{Nester1{Strs: []string{"zebra", "wally"}}, Nester1{Strs: []string{"qubert", "rocks"}}}},
			}

			var o bytes.Buffer
			rw.Save(&o)

			seg, n, err := capn.ReadFromMemoryZeroCopy(o.Bytes())
			cv.So(err, cv.ShouldEqual, nil)
			cv.So(n, cv.ShouldBeGreaterThan, 0)

			text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "RWTestCapn")

			if false {
				fmt.Printf("text = '%s'\n", text)
			}

			rw2 := &RWTest{}
			rw2.Load(&o)

			//fmt.Printf("rw = '%#v'\n", rw)
			//fmt.Printf("rw2 = '%#v'\n", rw2)

			same := reflect.DeepEqual(&rw, rw2)
			cv.So(same, cv.ShouldEqual, true)
		})
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:34,代码来源:nested_test.go

示例14: Test001StructList

// start with smaller Struct(List)
func Test001StructList(t *testing.T) {

	cv.Convey("Given type Nester1 struct { Strs []string } in go, where Nester1 is a struct, and a mirror/parallel capnp struct air.Nester1Capn { strs @0: List(Text); } defined in the aircraftlib schema", t, func() {
		cv.Convey("When we Save() Nester to capn and then Load() it back, the data should match, so that we have working Struct(List) serialization and deserializatoin in go-capnproto", func() {

			// Does Nester1 alone serialization and deser okay?
			rw := Nester1{Strs: []string{"xenophilia", "watchowski"}}

			var o bytes.Buffer
			rw.Save(&o)

			seg, n, err := capn.ReadFromMemoryZeroCopy(o.Bytes())
			cv.So(err, cv.ShouldEqual, nil)
			cv.So(n, cv.ShouldBeGreaterThan, 0)

			text := CapnpDecodeSegment(seg, "", "aircraftlib/aircraft.capnp", "Nester1Capn")
			if false {
				fmt.Printf("text = '%s'\n", text)
			}
			rw2 := &Nester1{}
			rw2.Load(&o)

			//fmt.Printf("rw = '%#v'\n", rw)
			//fmt.Printf("rw2 = '%#v'\n", rw2)

			same := reflect.DeepEqual(&rw, rw2)
			cv.So(same, cv.ShouldEqual, true)
		})
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:31,代码来源:nested_test.go

示例15: TestTextContaintingStruct

func TestTextContaintingStruct(t *testing.T) {

	zjobBytes := CapnpEncode(`(cmd = "abc")`, "Zjob")

	cv.Convey("Given a simple struct message Zjob containing a string 'abc' and a list of string (empty)", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {

			seg := capn.NewBuffer(nil)
			zjob := air.NewRootZjob(seg)
			zjob.SetCmd("abc")

			buf := bytes.Buffer{}
			seg.WriteTo(&buf)

			act := buf.Bytes()
			fmt.Printf("          actual:\n")
			ShowBytes(act, 10)

			fmt.Printf("\n\n          expected:\n")
			ShowBytes(zjobBytes, 10)

			cv.So(act, cv.ShouldResemble, zjobBytes)
		})
	})
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:25,代码来源:struct_test.go


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