Exemplo n.º 1
0
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)
		}
	}
}
Exemplo n.º 2
0
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)
	})
}
Exemplo n.º 3
0
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")
		})

	})
}
Exemplo n.º 4
0
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)
			})
		})
	})
}
Exemplo n.º 5
0
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)
		})
	})
}
Exemplo n.º 6
0
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)
	})
}
Exemplo n.º 7
0
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)

		})
	})
}
Exemplo n.º 8
0
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)
	})
}
Exemplo n.º 9
0
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)
	})
}
Exemplo n.º 10
0
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)
	})
}
Exemplo n.º 11
0
// 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")
	})
}
Exemplo n.º 12
0
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)
	})
}
Exemplo n.º 13
0
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)
	})
}
Exemplo n.º 14
0
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)
	})
}
Exemplo n.º 15
0
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)
	})

}
Exemplo n.º 16
0
func TestWrite(t *testing.T) {
	c.Convey("Given DefaultWriter", t, func() {
		Writer = DefaultWriter{}
		c.Convey("Write should go to stdout", func() {
			count, err := Writer.Write([]byte("test"))
			c.So(err, c.ShouldBeNil)
			c.So(count, c.ShouldEqual, 4)
		})
	})
}
Exemplo n.º 17
0
func TestConfig(t *testing.T) {
	test := Config()
	convey.Convey("test should not be nil", t, func() {
		convey.So(test, convey.ShouldNotEqual, nil)
	})
	addr := test.GetString("addr")
	convey.Convey("addr should not be localhost:8081", t, func() {
		convey.So(addr, convey.ShouldEqual, "localhost:8081")
	})
}
Exemplo n.º 18
0
func TestAsyncWrite(t *testing.T) {
	c.Convey("Given AsyncWriter", t, func() {
		Writer = NewAsyncWriter()
		c.Convey("Should return 0 bytes and no error", func() {
			count, err := Writer.Write([]byte("test"))
			c.So(count, c.ShouldBeZeroValue)
			c.So(err, c.ShouldBeNil)
		})
	})
}
Exemplo n.º 19
0
func TestTake(t *testing.T) {
	c.Convey("Previous error is reflected in result", t, func() {
		_, err := From(arr0).Where(erroneusBinaryFunc).Take(1).Results()
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("Empty slice take n>0", t, func() {
		res, err := From(empty).Take(1).Results()
		c.So(err, c.ShouldEqual, nil)
		c.So(res, shouldSlicesResemble, empty)
	})

	c.Convey("Take 0", t, func() {
		res, _ := From(arr0).Take(0).Results()
		c.So(res, shouldSlicesResemble, empty)
	})

	c.Convey("Take n < 0", t, func() {
		res, err := From(arr0).Take(-1).Results()
		c.So(err, c.ShouldEqual, nil)
		c.So(res, shouldSlicesResemble, empty)
	})

	c.Convey("Take n > 0", t, func() {
		in := []int{1, 2, 3, 4, 5}
		res, _ := From(in).Take(3).Results()
		c.So(res, shouldSlicesResemble, []int{1, 2, 3})
		c.Convey("Take n ≥ len(arr)", func() {
			res, _ := From(in).Take(len(in)).Results()
			c.So(res, shouldSlicesResemble, res)
			res, _ = From(in).Take(len(in) + 1).Results()
			c.So(res, shouldSlicesResemble, res)
		})
	})
}
Exemplo n.º 20
0
func TestSingleParallel(t *testing.T) {
	c.Convey("Previous error is reflected on result", t, func() {
		_, err := From(arr0).AsParallel().Where(erroneusBinaryFunc).Single(nil)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("Given a nil function, ErrNilFunc is returned", t, func() {
		_, err := From(arr0).AsParallel().Where(alwaysTrueDelayed).Single(nil)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("An error returned from f is reflected on Result", t, func() {
		_, err := From(arr0).AsParallel().Where(alwaysTrueDelayed).Single(erroneusBinaryFunc)
		c.So(err, c.ShouldNotEqual, nil)
		c.So(err, c.ShouldNotEqual, ErrNotSingle)
		_, err = From(arr0).AsParallel().Where(alwaysFalseDelayed).Single(erroneusBinaryFunc)
		c.So(err, c.ShouldEqual, ErrNotSingle)
	})
	c.Convey("No matches", t, func() {
		_, err := From(arr0).AsParallel().Single(alwaysFalseDelayed)
		c.So(err, c.ShouldEqual, ErrNotSingle)
	})
	c.Convey("All matches", t, func() {
		_, err := From(arr0).AsParallel().Single(alwaysTrueDelayed)
		c.So(err, c.ShouldEqual, ErrNotSingle)
	})
	c.Convey("Only one match", t, func() {
		match := 0
		var match0 = func(i T) (bool, error) {
			return i.(int) == match, nil
		}
		r, _ := From([]T{-1, -1, 0, 1, 1}).AsParallel().Single(match0)
		c.So(r, c.ShouldEqual, match)
		_, err := From([]T{0, 1, 2, 2, 0}).AsParallel().Single(match0)
		c.So(err, c.ShouldEqual, ErrNotSingle)
	})
}
Exemplo n.º 21
0
func TestCheckMapInterfaceInterface(t *testing.T) {
	log.Print("TesCheckMapInterfaceInterface")
	mapInterface = make(map[interface{}]interface{})
	convey.Convey("CheckMapInterfaceInterface(mapInterface) should be true", t, func() {
		convey.So(CheckMapInterfaceInterface(mapInterface), convey.ShouldEqual, true)
	})
	arrayOfInterface = make([]interface{}, 0)
	convey.Convey("CheckMapInterfaceInterface(arrayOfInterface) should be false", t, func() {
		convey.So(CheckMapInterfaceInterface(arrayOfInterface), convey.ShouldEqual, false)
	})
}
Exemplo n.º 22
0
func TestAddHalfStep(t *testing.T) {
	convey.Convey("Given value", t, func() {
		n := Note{Note: A, Octave: 4}
		expected := Note{Note: C, Octave: 5}

		convey.So(n.AddHalfSteps(3), convey.ShouldResemble, expected)

		expected = Note{Note: G, Octave: 4}
		convey.So(Note{Note: C, Octave: 5}.AddHalfSteps(-5), convey.ShouldResemble, expected)
	})
}
Exemplo n.º 23
0
func TestCritical(t *testing.T) {
	c.Convey("Given a MockWriter", t, func() {
		writer := &MockWriter{}
		Writer = writer
		c.Convey("When Level is LevelCritical", func() {
			Level = LevelCritical
			c.So(func() { Fatal("fatal") }, c.ShouldPanic)
			c.So(writer.GetLastLog(), c.ShouldEqual, "fatal")
		})
	})
}
Exemplo n.º 24
0
func TestMultiWriter(t *testing.T) {
	c.Convey("Given two writers", t, func() {
		writer1 := &MockWriter{}
		writer2 := &MockWriter{}
		Writer = nil
		AddWriter(writer1)
		AddWriter(writer2)
		Println("testmulti")
		c.So(writer1.GetLastLog(), c.ShouldEqual, "testmulti")
		c.So(writer2.GetLastLog(), c.ShouldEqual, "testmulti")
	})
}
func TestParseWsrepProviderOptions(t *testing.T) {
	testE := ""
	testM := "base_dir = /var/lib/mysql/; base_host = 10.91.142.82; base_port = 4567; cert.log_conflicts = no; debug = no; evs.auto_evict = 0; evs.causal_keepalive_period = PT1S; evs.debug_log_mask = 0x1; evs.delay_margin = PT1S; evs.delayed_keep_period = PT30S; evs.inactive_check_period = PT0.5S; evs.inactive_timeout = PT15S; evs.info_log_mask = 0; evs.install_timeout = PT7.5S; evs.join_retrans_period = PT1S; evs.keepalive_period = PT1S; evs.max_install_timeouts = 3; evs.send_window = 4; evs.stats_report_period = PT1M; evs.suspect_timeout = PT5S; evs.use_aggregate = true; evs.user_send_window = 2; evs.version = 0; evs.view_forget_timeout = P1D; gcache.dir = /var/lib/mysql/; gcache.keep_pages_count = 0; gcache.keep_pages_size = 0; gcache.mem_size = 0; gcache.name = /var/lib/mysql//galera.cache; gcache.page_size = 128M; gcache.size = 128M; gcomm.thread_prio = ; gcs.fc_debug = 0; gcs.fc_factor = 1.0; gcs.fc_limit = 16; gcs.fc_master_slave = no; gcs.max_packet_size = 64500; gcs.max_throttle = 0.25; gcs.recv_q_hard_limit = 9223372036854775807; gcs.recv_q_soft_limit = 0.25; gcs.sync_donor = no; gmcast.listen_addr = tcp://0.0.0.0:4567; gmcast.mcast_addr = ; gmcast.mcast_ttl = 1; gmcast.peer_timeout = PT3S; gmcast.segment = 0; gmcast.time_wait = PT5S; gmcast.version = 0; ist.recv_addr = 10.91.142.82; pc.announce_timeout = PT3S; pc.checksum = false; pc.ignore_quorum = false; pc.ignore_sb = false; pc.linger = PT20S; pc.npvo = false; pc.recovery = true; pc.version = 0; pc.wait_prim = true; pc.wait_prim_timeout = P30S; pc.weight = 1; protonet.backend = asio; protonet.version = 0; repl.causal_read_timeout = PT30S; repl.commit_order = 3; repl.key_format = FLAT8; repl.max_ws_size = 2147483647; repl.proto_max = 7; socket.checksum = 2; socket.recv_buf_size = 212992;"
	testG := "base_dir = /var/lib/mysql/; base_host = 10.91.194.244; base_port = 4567; cert.log_conflicts = no; debug = no; evs.auto_evict = 0; evs.causal_keepalive_period = PT1S; evs.debug_log_mask = 0x1; evs.delay_margin = PT1S; evs.delayed_keep_period = PT30S; evs.inactive_check_period = PT0.5S; evs.inactive_timeout = PT15S; evs.info_log_mask = 0; evs.install_timeout = PT7.5S; evs.join_retrans_period = PT1S; evs.keepalive_period = PT1S; evs.max_install_timeouts = 3; evs.send_window = 4; evs.stats_report_period = PT1M; evs.suspect_timeout = PT5S; evs.use_aggregate = true; evs.user_send_window = 2; evs.version = 0; evs.view_forget_timeout = P1D; gcache.dir = /var/lib/mysql/; gcache.keep_pages_count = 0; gcache.keep_pages_size = 0; gcache.mem_size = 0; gcache.name = /var/lib/mysql//galera.cache; gcache.page_size = 128M; gcache.size = 2G; gcomm.thread_prio = ; gcs.fc_debug = 0; gcs.fc_factor = 1.0; gcs.fc_limit = 16; gcs.fc_master_slave = no; gcs.max_packet_size = 64500; gcs.max_throttle = 0.25; gcs.recv_q_hard_limit = 9223372036854775807; gcs.recv_q_soft_limit = 0.25; gcs.sync_donor = no; gmcast.listen_addr = tcp://0.0.0.0:4567; gmcast.mcast_addr = ; gmcast.mcast_ttl = 1; gmcast.peer_timeout = PT3S; gmcast.segment = 0; gmcast.time_wait = PT5S; gmcast.version = 0; ist.recv_addr = 10.91.194.244; pc.announce_timeout = PT3S; pc.checksum = false; pc.ignore_quorum = false; pc.ignore_sb = false; pc.linger = PT20S; pc.npvo = false; pc.recovery = true; pc.version = 0; pc.wait_prim = true; pc.wait_prim_timeout = P30S; pc.weight = 1; protonet.backend = asio; protonet.version = 0; repl.causal_read_timeout = PT30S; repl.commit_order = 3; repl.key_format = FLAT8; repl.max_ws_size = 2147483647; repl.proto_max = 7; socket.checksum = 2; socket.recv_buf_size = 212992;"
	testB := "gcache.page_size = 128M; gcache.size = 131072; gcomm.thread_prio = ;"
	convey.Convey("Parse wsrep_provider_options", t, func() {
		convey.So(parseWsrepProviderOptions(testE), convey.ShouldEqual, 0)
		convey.So(parseWsrepProviderOptions(testM), convey.ShouldEqual, 128*1024*1024)
		convey.So(parseWsrepProviderOptions(testG), convey.ShouldEqual, 2*1024*1024*1024)
		convey.So(parseWsrepProviderOptions(testB), convey.ShouldEqual, 131072)
	})
}
Exemplo n.º 26
0
func TestCompact(t *testing.T) {

	cv.Convey("Given a big table with no values it, Compact() should re-allocate it to be smaller", t, func() {
		h := offheap.NewHashTable(128)
		cv.So(h.ArraySize, cv.ShouldEqual, 128)
		cv.So(h.Population, cv.ShouldEqual, 0)

		h.Compact()

		cv.So(h.ArraySize, cv.ShouldEqual, 1)
		cv.So(h.Population, cv.ShouldEqual, 0)
	})

}
Exemplo n.º 27
0
func TestAnyWithParallel(t *testing.T) {
	c.Convey("Previous error is reflected on result", t, func() {
		_, err := From(arr0).Where(erroneusBinaryFunc).AsParallel().AnyWith(alwaysTrueDelayed)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("Given a nil function, ErrNilFunc is returned", t, func() {
		_, err := From(arr0).Where(alwaysTrueDelayed).AsParallel().AnyWith(nil)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("An error returned from f is reflected on Result", t, func() {
		_, err := From(arr0).Where(alwaysTrueDelayed).AsParallel().AnyWith(erroneusBinaryFunc)
		c.So(err, c.ShouldNotEqual, nil)
		_, err = From(arr0).Where(alwaysFalse).AsParallel().AnyWith(erroneusBinaryFunc)
		c.So(err, c.ShouldEqual, nil)
	})
	c.Convey("No matches", t, func() {
		r, _ := From(arr0).AsParallel().AnyWith(alwaysFalseDelayed)
		c.So(r, c.ShouldEqual, false)
		r, _ = From(arr0).AsParallel().Where(alwaysFalseDelayed).Any()
		c.So(r, c.ShouldEqual, false)
	})
	c.Convey("All matches", t, func() {
		r, _ := From(arr0).AsParallel().AnyWith(alwaysTrueDelayed)
		c.So(r, c.ShouldEqual, true)
		r, _ = From(arr0).AsParallel().Where(alwaysTrueDelayed).Any()
		c.So(r, c.ShouldEqual, true)
	})
}
Exemplo n.º 28
0
func TestSetFromEnv(t *testing.T) {
	var err error
	os.Setenv(fmt.Sprintf("%s%s", ENV_PREFIX, "StringDefaultNotEmpty"), "FooFromEnv")
	cfg := struct {
		Config

		StringDefaultNotEmpty string `required:"true" should:"NotBeBlank"`
	}{}
	err = InitConfig(&cfg)
	cv.Convey(`Initializing a config with a required should:"NotBeEmpty" string value should pass initialization when the prefixed key is set on the OS.ENV.`, t, func() {
		cv.So(err, cv.ShouldBeNil)
		cv.So(cfg.StringDefaultNotEmpty, cv.ShouldEqual, "FooFromEnv")
	})
}
Exemplo n.º 29
0
func TestAllParallel(t *testing.T) {
	c.Convey("Previous error is reflected on result", t, func() {
		_, err := From(arr0).Where(erroneusBinaryFunc).AsParallel().All(nil)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("Given a nil function, ErrNilFunc is returned", t, func() {
		_, err := From(arr0).Where(alwaysTrue).AsParallel().All(nil)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("An error returned from f is reflected on Result", t, func() {
		_, err := From(arr0).Where(alwaysTrue).AsParallel().All(erroneusBinaryFunc)
		c.So(err, c.ShouldNotEqual, nil)
		_, err = From(arr0).Where(alwaysFalse).AsParallel().All(erroneusBinaryFunc)
		c.So(err, c.ShouldEqual, nil)
	})
	c.Convey("Empty slice", t, func() {
		r, _ := From(empty).AsParallel().All(alwaysTrueDelayed)
		c.So(r, c.ShouldEqual, true)
	})
	c.Convey("No matches", t, func() {
		r, _ := From(arr0).AsParallel().All(alwaysFalseDelayed)
		c.So(r, c.ShouldEqual, false)
	})
	c.Convey("All matches", t, func() {
		r, _ := From(arr0).AsParallel().All(alwaysTrueDelayed)
		c.So(r, c.ShouldEqual, true)
	})
	c.Convey("Multiple matches", t, func() {
		match0 := func(i T) (bool, error) {
			return i.(int) == 0, nil
		}
		r, _ := From([]T{0, 1, 2, 2, 0}).AsParallel().All(match0)
		c.So(r, c.ShouldEqual, false)
	})
}
Exemplo n.º 30
0
func TestCountParallel(t *testing.T) {
	c.Convey("Previous error is reflected on result", t, func() {
		_, err := From(arr0).AsParallel().Where(erroneusBinaryFunc).CountBy(erroneusBinaryFunc)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("Given a nil function, ErrNilFunc is returned", t, func() {
		_, err := From(arr0).AsParallel().Where(alwaysTrueDelayed).CountBy(nil)
		c.So(err, c.ShouldNotEqual, nil)
	})
	c.Convey("An error returned from f is reflected on Result", t, func() {
		_, err := From(arr0).AsParallel().Where(alwaysTrueDelayed).CountBy(erroneusBinaryFunc)
		c.So(err, c.ShouldNotEqual, nil)
		_, err = From(arr0).AsParallel().Where(alwaysFalseDelayed).CountBy(erroneusBinaryFunc)
		c.So(err, c.ShouldEqual, nil)
	})
	c.Convey("No matches", t, func() {
		cnt, _ := From(arr0).AsParallel().CountBy(alwaysFalseDelayed)
		c.So(cnt, c.ShouldEqual, 0)
		cnt, _ = From(arr0).AsParallel().Where(alwaysFalseDelayed).Count()
		c.So(cnt, c.ShouldEqual, 0)
	})
	c.Convey("All matches", t, func() {
		cnt, _ := From(arr0).AsParallel().CountBy(alwaysTrueDelayed)
		c.So(cnt, c.ShouldEqual, len(arr0))
		cnt, _ = From(arr0).AsParallel().Count()
		c.So(cnt, c.ShouldEqual, len(arr0))
	})
}