Beispiel #1
0
func TestInvalidWhenStringIsTooShort(t *testing.T) {
	spec := gspec.New(t)
	rule := MinLen(4)
	for _, str := range []string{"1", "12", "123"} {
		spec.Expect(rule.Verify(str)).ToEqual(false)
	}
}
Beispiel #2
0
func TestInvalidWhenStringIsTooLong(t *testing.T) {
	spec := gspec.New(t)
	rule := MaxLen(4)
	for _, str := range []string{"12345", "123456"} {
		spec.Expect(rule.Verify(str)).ToEqual(false)
	}
}
Beispiel #3
0
func TestParserReadsContainsCondition(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" 'xyz'   contains   true%}")
	group, err := parser.ReadConditionGroup()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, "xyz", Contains, true)
}
Beispiel #4
0
func TestSetsTheNotFoundResponse(t *testing.T) {
	spec := gspec.New(t)
	expected := Json("the res").Status(244).Response
	actual := Configure().NotFoundResponse(expected).notFound
	spec.Expect(actual.GetStatus()).ToEqual(244)
	spec.Expect(string(actual.GetBody())).ToEqual("the res")
}
Beispiel #5
0
func TestReverseASingleElementArray(t *testing.T) {
	spec := gspec.New(t)
	filter := ReverseFactory(nil)
	values := filter([]bool{true}, nil).([]bool)
	spec.Expect(len(values)).ToEqual(1)
	spec.Expect(values[0]).ToEqual(true)
}
Beispiel #6
0
func TestSetContainsAnExistingIdIfMultipleIndexesContainsIt(t *testing.T) {
	spec := gspec.New(t)
	union := NewUnion("x", []string{"apple", "orange"})
	union.On(makeSetIndex(20, 23, 24, 25, 26))
	union.On(makeSetIndex(20, 25, 28, 29))
	spec.Expect(union.Contains(key.Type(20))).ToEqual(true)
}
Beispiel #7
0
func TestValidWhenStringLengthIsWithinLen(t *testing.T) {
	spec := gspec.New(t)
	rule := Len(4, 6)
	for _, str := range []string{"1234", "12345", "123456"} {
		spec.Expect(rule.Verify(str)).ToEqual(true)
	}
}
Beispiel #8
0
func TestMockIsLimitedToASingleInvocation(t *testing.T) {
	spec := gspec.New(t)
	fake := newFake()
	fake.Expect(fake.GetEmail).Returning("first").Once()
	spec.Expect(fake.GetEmail("leto")).ToEqual("first")
	spec.Expect(fake.GetEmail("paul")).ToEqual("*****@*****.**")
}
Beispiel #9
0
func TestMockReturnsTheValueOnceByDefaultTimes(t *testing.T) {
	spec := gspec.New(t)
	fake := newFake()
	fake.Expect(fake.GetEmail).Returning("invalid")
	spec.Expect(fake.GetEmail("leto")).ToEqual("invalid")
	spec.Expect(fake.GetEmail("paul")).ToEqual("*****@*****.**")
}
Beispiel #10
0
func assertStaticValue(t *testing.T, data string, expected interface{}) {
	spec := gspec.New(t)
	p := NewParser([]byte(data))
	value, err := p.ReadValue()
	spec.Expect(err).ToBeNil()
	spec.Expect(value.Resolve(nil)).ToEqual(expected)
}
Beispiel #11
0
func assertErrorValue(t *testing.T, data string, expected string) {
	spec := gspec.New(t)
	p := NewParser([]byte(data))
	value, err := p.ReadValue()
	spec.Expect(err.Error()).ToEqual(expected)
	spec.Expect(value).ToBeNil()
}
Beispiel #12
0
func TestStubReturnsTheValueMultipleTimes(t *testing.T) {
	spec := gspec.New(t)
	fake := newFake()
	fake.Stub(fake.GetEmail).Returning("invalid")
	spec.Expect(fake.GetEmail("leto")).ToEqual("invalid")
	spec.Expect(fake.GetEmail("paul")).ToEqual("invalid")
}
Beispiel #13
0
func TestQueryCapsTheLimit(t *testing.T) {
	spec := gspec.New(t)
	db := SmallDB()
	defer db.Close()
	query := <-db.queryPool
	spec.Expect(query.Limit(200).(*NormalQuery).limit).ToEqual(100)
}
Beispiel #14
0
func TestEmptyQueryOnInvalidIndex(t *testing.T) {
	spec := gspec.New(t)
	db := SmallDB()
	defer db.Close()
	_, ok := db.Query("cats").(*EmptyQuery)
	spec.Expect(ok).ToEqual(true)
}
Beispiel #15
0
func TestParserReadsASinglePartial(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" true %}")
	group, err := parser.ReadPartialCondition()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, true, UnknownComparator, nil)
}
Beispiel #16
0
func TestIdMapReturnsAnExistingId(t *testing.T) {
	spec := gspec.New(t)
	m := newIdMap()
	m.get("over", true)
	m.get("9000", true)
	spec.Expect(m.get("over", false)).ToEqual(key.Type(1))
}
Beispiel #17
0
func TestParserReadsMultiplePartials(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" 1 or 2%}")
	group, err := parser.ReadPartialCondition()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, 1, UnknownComparator, nil, OR, 2, UnknownComparator, nil)
}
Beispiel #18
0
func TestIdMapRemovesAnId(t *testing.T) {
	spec := gspec.New(t)
	m := newIdMap()
	m.get("over", true)
	m.remove("over")
	spec.Expect(m.get("over", false)).ToEqual(key.NULL)
}
Beispiel #19
0
func TestUnionDoesNotContainANonExistantId(t *testing.T) {
	spec := gspec.New(t)
	union := NewUnion("x", []string{"apple", "orange"})
	union.On(makeSetIndex(20, 23, 24, 25, 26))
	union.On(makeSetIndex(20, 25, 28, 29))
	spec.Expect(union.Contains(key.Type(22))).ToEqual(false)
}
Beispiel #20
0
func TestParserReadsAUnaryCondition(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" true %}")
	group, err := parser.ReadConditionGroup()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, true, Unary, nil)
}
Beispiel #21
0
func TestInvalidWhenStringLengthIsOutsideLen(t *testing.T) {
	spec := gspec.New(t)
	rule := Len(4, 6)
	for _, str := range []string{"123", "12", "1234567", "12345678"} {
		spec.Expect(rule.Verify(str)).ToEqual(false)
	}
}
Beispiel #22
0
func TestParserReadsMultipleUnaryConditions(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" true and false%}")
	group, err := parser.ReadConditionGroup()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, true, Unary, nil, AND, false, Unary, nil)
}
Beispiel #23
0
func TestSetsTheBodyPoolSize(t *testing.T) {
	spec := gspec.New(t)
	c := Configure().BodyPool(10, 16)
	//allocate 1 extra byte so we know if the body is too large (or just right)
	spec.Expect(c.maxBodySize).ToEqual(int64(17))
	spec.Expect(c.bodyPoolSize).ToEqual(10)
}
Beispiel #24
0
func TestParserReadsSingleCondition(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" true == 123   %}")
	group, err := parser.ReadConditionGroup()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, true, Equals, 123)
}
Beispiel #25
0
func TestValidWhenStringIsShorterThanMaxLen(t *testing.T) {
	spec := gspec.New(t)
	rule := MaxLen(4)
	for _, str := range []string{"1", "12", "123", "1234"} {
		spec.Expect(rule.Verify(str)).ToEqual(true)
	}
}
Beispiel #26
0
func TestParserReadsMultipleComplexConditions(t *testing.T) {
	spec := gspec.New(t)
	parser := newParser(" 'xyz'   contains   true or true and 123 > 445%}")
	group, err := parser.ReadConditionGroup()
	spec.Expect(err).ToBeNil()
	assertParsedConditionGroup(t, group, "xyz", Contains, true, OR, true, Unary, nil, AND, 123, GreaterThan, 445)
}
Beispiel #27
0
func TestEmptyBackwards(t *testing.T) {
	spec := gspec.New(t)
	empty := NewEmpty("x")
	empty.Set(key.Type(4))
	iter := empty.Backwards()
	spec.Expect(iter.Current()).ToEqual(key.NULL)
}
Beispiel #28
0
func TestEmptyLength(t *testing.T) {
	spec := gspec.New(t)
	empty := NewEmpty("x")
	empty.Set(key.Type(4))
	empty.Set(key.Type(6))
	spec.Expect(empty.Len()).ToEqual(0)
}
Beispiel #29
0
func TestValidWhenStringIsLongerThanMinLen(t *testing.T) {
	spec := gspec.New(t)
	rule := MinLen(4)
	for _, str := range []string{"1234", "12345", "123456"} {
		spec.Expect(rule.Verify(str)).ToEqual(true)
	}
}
Beispiel #30
0
func TestSplitsAStringOnDefaultSpace(t *testing.T) {
	spec := gspec.New(t)
	filter := SplitFactory([]core.Value{})
	values := filter("hello world", nil).([]string)
	spec.Expect(len(values)).ToEqual(2)
	spec.Expect(values[0]).ToEqual("hello")
	spec.Expect(values[1]).ToEqual("world")
}