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


Golang convey.So函数代码示例

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


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

示例1: TestNewUUID

func TestNewUUID(t *testing.T) {
	uuid := NewUUID()
	convey.Convey("uuid should not be nil", t, func() {
		convey.So(uuid, convey.ShouldNotEqual, nil)
	})
	uuid2 := NewUUID()
	convey.Convey("uuid should not be equl to uuid", t, func() {
		convey.So(uuid, convey.ShouldNotEqual, uuid2)
	})

	for i := 0; i < 100; i++ {
		u := NewUUID()
		str := u.String()
		version := str[14:15]
		key := str[19:20]

		//		convey.Convey("uuid Version should not be equl to 4", t, func() {
		//			convey.So(version, convey.ShouldEqual, "4")
		//		})

		if version != "4" {
			t.Error("Version must Be == 4 not ", version, " in ", str)
		}
		if key != "8" && key != "9" && key != "a" && key != "b" {
			t.Error("key must be Equal 8, 9, a, b not:", key, " in ", str)
		}
	}
}
开发者ID:NexwayGroup,项目名称:nx-lib,代码行数:28,代码来源:UUID_test.go

示例2: TestGroupBy

func TestGroupBy(t *testing.T) {
	c.Convey("Group empty slice into empty map", t, func() {
		res, err := From(empty).GroupBy(func(foo T) T { return foo }, func(foo T) T { return foo })
		c.So(err, c.ShouldEqual, nil)
		c.So(res, c.ShouldResemble, make(map[T][]T))
	})

	type Pet struct {
		Name  string
		Owner string
	}

	barley := Pet{Name: "Barley", Owner: "Damon Zhao"}
	boots := Pet{Name: "Boots", Owner: "Damon Zhao"}
	whiskers := Pet{Name: "Whiskers", Owner: "A-limon"}
	daisy := Pet{Name: "Daisy", Owner: "A-limon"}
	sasha := Pet{Name: "Sasha", Owner: "Bob"}

	pets := []Pet{barley, boots, whiskers, daisy, sasha}

	groupByExpected := map[T][]T{
		"Damon Zhao": []T{barley.Name, boots.Name},
		"A-limon":    []T{whiskers.Name, daisy.Name},
		"Bob":        []T{sasha.Name},
	}

	c.Convey("Pets group by owner", t, func() {
		res, err := From(pets).GroupBy(func(pet T) T { return pet.(Pet).Owner }, func(pet T) T { return pet.(Pet).Name })
		c.So(err, c.ShouldEqual, nil)
		c.So(res, c.ShouldResemble, groupByExpected)
	})
}
开发者ID:psarathi,项目名称:go-linq,代码行数:32,代码来源:linq_test.go

示例3: TestFormat

func TestFormat(t *testing.T) {
	c.Convey("Given format funcs", t, func() {
		funcs := map[string]func(string, ...interface{}){
			"Printf":   Printf,
			"Tracef":   Tracef,
			"Debugf":   Debugf,
			"Infof":    Infof,
			"Warningf": Warningf,
			"Errorf":   Errorf,
		}
		writer := &MockWriter{}
		Writer = writer
		Level = LevelTrace
		for name, fun := range funcs {
			c.Convey(name+" format should work", func() {
				fun("%s answer: %d", name, 42)
				c.So(writer.GetLastLog(), c.ShouldEqual, name+" answer: 42")
			})
		}
		c.Convey("Fatalf format should work", func() {
			c.So(func() { Fatalf("answer: %d", 42) }, c.ShouldPanic)
			c.So(writer.GetLastLog(), c.ShouldEqual, "answer: 42")
		})

	})
}
开发者ID:serejja,项目名称:log,代码行数:26,代码来源:log_test.go

示例4: TestHyphenArgNotFlag

func TestHyphenArgNotFlag(t *testing.T) {
	gc.Convey("Given a flagset and some args, including a hyphen", t, func() {

		f := &flag.FlagSet{}
		isF := f.Bool("f", false, "")
		isX := f.Bool("x", false, "")
		args := []string{"-f", "-"}

		gc.Convey("When parsing the args", func() {

			f.Parse(args)

			gc.Convey("There should only by one flag parsed", func() {

				gc.So(f.NFlag(), gc.ShouldEqual, 1)

				gc.Convey("And it should be \"-f\"", func() {

					gc.So(*isF, gc.ShouldBeTrue)

					gc.Convey("And not \"-x\"", func() {
						gc.So(*isX, gc.ShouldBeFalse)
					})
				})
			})

			gc.Convey("There should only be one arg parsed", func() {
				gc.So(f.NArg(), gc.ShouldEqual, 1)
			})
		})
	})
}
开发者ID:homburg,项目名称:envoke,代码行数:32,代码来源:flag_test.go

示例5: TestResolveAndReject

func TestResolveAndReject(t *testing.T) {
	c.Convey("When Promise is resolved", t, func() {
		p := NewPromise()
		go func() {
			time.Sleep(50 * time.Millisecond)
			p.Resolve("ok")
		}()
		c.Convey("Should return the argument of Resolve", func() {
			r, err := p.Get()
			c.So(r, c.ShouldEqual, "ok")
			c.So(err, c.ShouldBeNil)
		})
	})

	c.Convey("When Promise is rejected", t, func() {
		p := NewPromise()
		go func() {
			time.Sleep(50 * time.Millisecond)
			p.Reject(errors.New("fail"))
		}()
		c.Convey("Should return error", func() {
			r, err := p.Get()
			c.So(err, c.ShouldNotBeNil)
			c.So(r, c.ShouldEqual, nil)
		})
	})
}
开发者ID:aganno2,项目名称:go-promise,代码行数:27,代码来源:future_test.go

示例6: TestWrap

func TestWrap(t *testing.T) {
	c.Convey("Test Wrap a value", t, func() {
		r, err := Wrap(10).Get()
		c.So(r, c.ShouldEqual, 10)
		c.So(err, c.ShouldBeNil)
	})
}
开发者ID:aganno2,项目名称:go-promise,代码行数:7,代码来源:future_test.go

示例7: TestCertGen

func TestCertGen(t *testing.T) {
	origdir, tmpdir := GenTempDir()
	//fmt.Printf("attempting to generate certs in tempdir: '%s'\n", tmpdir)

	defer CleanupTempDir(origdir, tmpdir)

	cv.Convey("Given a built generate_cert/generate_cert utility program", t, func() {

		cv.Convey("it should generate certs in our temp directory of the expected file length.", func() {

			c := exec.Command(origdir + "/generate_cert/generate_cert")
			_, err := c.Output()
			if err != nil {
				panic(err)
			}
			certExists, certFi := FileExists(tmpdir + "/cert.pem")
			keyExists, keyFi := FileExists(tmpdir + "/key.pem")

			//fmt.Printf("certFi = %#v\n", certFi)
			//fmt.Printf("keyFi  = %#v\n", keyFi)

			cv.So(certExists, cv.ShouldEqual, true)
			cv.So(keyExists, cv.ShouldEqual, true)

			cv.So(certFi.Size(), cv.ShouldEqual, 1074)
			cv.So(keyFi.Size(), cv.ShouldBeGreaterThan, 1600)

		})
	})
}
开发者ID:JasonAtenPivotal,项目名称:go-guerrilla,代码行数:30,代码来源:main_test.go

示例8: TestOrderBy

func TestOrderBy(t *testing.T) {
	unsorted := []*foo{&foo{"A", 5}, &foo{"B", 1}, &foo{"C", 3}}
	sorted := []*foo{&foo{"B", 1}, &foo{"C", 3}, &foo{"A", 5}}
	sortByNum := func(this T, that T) bool {
		_this := this.(*foo)
		_that := that.(*foo)
		return _this.num <= _that.num
	}

	c.Convey("Nil comparator passed", t, func() {
		_, err := From(unsorted).OrderBy(nil).Results()
		c.So(err, c.ShouldEqual, ErrNilFunc)
	})
	c.Convey("Previous error is reflected in result", t, func() {
		_, err := From(unsorted).Where(erroneusBinaryFunc).OrderBy(sortByNum).Results()
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("Sort empty", t, func() {
		res, _ := From(empty).OrderBy(sortByNum).Results()
		c.So(res, shouldSlicesResemble, empty)
	})
	c.Convey("Sort on structs", t, func() {
		res, _ := From(unsorted).OrderBy(sortByNum).Results()
		c.So(res, shouldSlicesResemble, sorted)
	})
}
开发者ID:psarathi,项目名称:go-linq,代码行数:26,代码来源:linq_test.go

示例9: TestElementAt

func TestElementAt(t *testing.T) {
	intArr := []int{1, 2, 3, 4, 5}
	c.Convey("empty.ElementAt(1) is not found", t, func() {
		_, ok, err := From(empty).ElementAt(1)
		c.So(ok, c.ShouldBeFalse)
		c.So(err, c.ShouldEqual, nil)
	})
	c.Convey("negative index returns is ErrNegativeParam", t, func() {
		_, _, err := From(empty).ElementAt(-1)
		c.So(err, c.ShouldEqual, ErrNegativeParam)
	})
	c.Convey("first element is returned", t, func() {
		v, ok, _ := From(intArr).ElementAt(0)
		c.So(ok, c.ShouldBeTrue)
		c.So(v, c.ShouldEqual, intArr[0])
	})
	c.Convey("last element is returned", t, func() {
		v, ok, _ := From(intArr).ElementAt(len(intArr) - 1)
		c.So(ok, c.ShouldBeTrue)
		c.So(v, c.ShouldEqual, intArr[len(intArr)-1])
	})
	c.Convey("out of index returns not found on non-empty slice", t, func() {
		_, ok, err := From(intArr).ElementAt(len(intArr))
		c.So(ok, c.ShouldBeFalse)
		c.So(err, c.ShouldEqual, nil)
	})
	c.Convey("previous errors are reflected", t, func() {
		_, _, err := From(arr0).Where(erroneusBinaryFunc).ElementAt(0)
		c.So(err, c.ShouldNotEqual, nil)
	})
}
开发者ID:psarathi,项目名称:go-linq,代码行数:31,代码来源:linq_test.go

示例10: shouldBeBadRequest

func shouldBeBadRequest(t *testing.T, res *http.Response, code services.CodeErr, message string) {
	c.Convey("Response should be 400 (Bad request)", func() {
		c.So(res.StatusCode, c.ShouldEqual, http.StatusBadRequest)
		e := getServiceError(t, res)
		c.So(e.Code, c.ShouldEqual, code)
		c.So(e.Message, c.ShouldEqual, message)
	})
}
开发者ID:iwarsong,项目名称:bearded,代码行数:8,代码来源:session_service_test.go

示例11: TestSessionId

// Simple test for representation of SessionId
func TestSessionId(t *testing.T) {
	c.Convey("Testing Session ID String()", t, func() {
		id := smtp.Id{Timestamp: 1446302030, Counter: 42}
		c.So(id.String(), c.ShouldEqual, "5634d14e2a")

		id = smtp.Id{Timestamp: 2147483648, Counter: 4294967295}
		c.So(id.String(), c.ShouldEqual, "80000000ffffffff")
	})
}
开发者ID:gopistolet,项目名称:smtp,代码行数:10,代码来源:mta_test.go

示例12: TestLoadConfig

func TestLoadConfig(t *testing.T) {
	LoadConfig("./", "configTest")
	convey.Convey("v should not be nil", t, func() {
		convey.So(v, convey.ShouldNotEqual, nil)
	})
	convey.Convey("v should not be nil", t, func() {
		convey.So(v, convey.ShouldNotEqual, nil)
	})
}
开发者ID:NexwayGroup,项目名称:nx-lib,代码行数:9,代码来源:main_test.go

示例13: TestCheckArrayInterface

func TestCheckArrayInterface(t *testing.T) {
	log.Print("TestCheckArrayInterface")
	convey.Convey("CheckMapInterfaceInterface(mapInterface) should be true", t, func() {
		convey.So(CheckArrayInterface(mapInterface), convey.ShouldEqual, false)
	})
	convey.Convey("CheckMapInterfaceInterface(arrayOfInterface) should be false", t, func() {
		convey.So(CheckArrayInterface(arrayOfInterface), convey.ShouldEqual, true)
	})
}
开发者ID:NexwayGroup,项目名称:nx-lib,代码行数:9,代码来源:cast_test.go

示例14: TestSelect

func TestSelect(t *testing.T) {
	asIs := func(i T) (T, error) {
		return i, nil
	}
	erroneusFunc := func(i T) (T, error) {
		return nil, errFoo
	}

	c.Convey("Previous error is reflected on result", t, func() {
		_, err := From(arr0).Where(erroneusBinaryFunc).Select(asIs).Results()
		c.So(err, c.ShouldNotEqual, nil)
	})

	c.Convey("Nil func returns error", t, func() {
		_, err := From(arr0).Select(nil).Results()
		c.So(err, c.ShouldEqual, ErrNilFunc)
	})

	c.Convey("Error returned from provided func", t, func() {
		val, err := From(arr0).Select(erroneusFunc).Results()
		c.So(err, c.ShouldNotEqual, nil)

		c.Convey("Erroneus function is in chain with as-is select", func() {
			_, err = From(arr0).Select(asIs).Select(erroneusFunc).Results()
			c.So(err, c.ShouldNotEqual, nil)
		})
		c.Convey("Erroneus function is in chain but not called", func() {
			val, err = From(arr0).Where(alwaysFalse).Select(erroneusFunc).Results()
			c.So(err, c.ShouldEqual, nil)
			c.So(len(val), c.ShouldEqual, 0)
		})

	})

	c.Convey("Select all elements as is", t, func() {
		val, err := From(arr0).Select(asIs).Results()
		c.So(err, c.ShouldEqual, nil)
		c.So(val, shouldSlicesResemble, arr0)
	})

	c.Convey("Pow(x,2) for i in []int", t, func() {
		pow := func(i T) (T, error) {
			return i.(int) * i.(int), nil
		}
		val, err := From(arr0).Select(pow).Results()
		c.So(err, c.ShouldEqual, nil)
		arr := make([]int, len(arr0))
		for j, i := range arr0 {
			arr[j] = i * i
		}
		res := make([]int, len(val))
		for j, v := range val {
			res[j] = v.(int)
		}
		c.So(res, shouldSlicesResemble, arr)
	})
}
开发者ID:psarathi,项目名称:go-linq,代码行数:57,代码来源:linq_test.go

示例15: TestLoadYaml

func TestLoadYaml(t *testing.T) {
	var err error
	cfg := struct {
		Config

		BoolSetting   bool    `required:"true"`
		StringSetting string  `required:"true"`
		IntSetting    int     `required:"true"`
		FloatSetting  float64 `required:"true"`

		SliceConfig struct {
			StringSliceSetting []string  `required:"true"`
			IntSliceSetting    []int     `required:"true"`
			FloatSliceSetting  []float64 `required:"true"`
		}
	}{}

	// initFunc := func() (err error) {
	// 	var yamlData []byte
	// 	yamlData, err = ioutil.ReadFile("test/test.yaml")
	// 	if err != nil {
	// 		return
	// 	}
	// 	v := [][]string{}
	// 	err = yaml.Unmarshal([]byte(yamlData), &v)
	// 	if err != nil {
	// 		return
	// 	}
	// 	log.Println(v)
	// 	log.Println(cfg)

	// 	err = cfg.Set(v)
	// 	return
	// }

	cv.Convey(`Initializing the config should pass.`, t, func() {
		err = InitConfig(&cfg)
		// cv.So(err, cv.ShouldBeNil)

		var yamlData []byte
		yamlData, err = ioutil.ReadFile("test/test.yaml")
		cv.So(err, cv.ShouldBeNil)

		v := [][]string{}
		err = yaml.Unmarshal([]byte(yamlData), &v)
		cv.So(err, cv.ShouldBeNil)

		t.Log("---", v)
		// log.Println(cfg)

		err = cfg.Set(v)
		t.Log(cfg.SliceConfig.StringSliceSetting)
		t.Log(cfg.SliceConfig.IntSliceSetting)
		// cv.So(err, cv.ShouldBeNil)
	})

}
开发者ID:fvbock,项目名称:confobject,代码行数:57,代码来源:confobject_test.go


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