Beispiel #1
0
func TestPanicIfTrue(t *testing.T) {
	assert := assert.New(t)

	arg := "arg value"
	format := "could be a format: %s"
	formatted := fmt.Sprintf(format, arg)

	assert.Panics(func() {
		PanicIfTrue(true, "Panicking!!!!")
	})

	assert.NotPanics(func() {
		PanicIfTrue(false, "Not panicking")
	})

	err := Try(func() {
		PanicIfTrue(true, format)
	})
	assert.Equal(errors.New(format), Unwrap(err))

	err = Try(func() {
		PanicIfTrue(true, format, arg)
	})
	assert.Equal(errors.New(formatted), Unwrap(err))
}
Beispiel #2
0
func TestMapTypeAfterMutations(t *testing.T) {
	assert := assert.New(t)

	test := func(n int, c interface{}) {
		values := make([]Value, 2*n)
		for i := 0; i < n; i++ {
			values[2*i] = Number(i)
			values[2*i+1] = Number(i)
		}

		m := NewMap(values...)
		assert.Equal(m.Len(), uint64(n))
		assert.IsType(c, m.sequence())
		assert.True(m.Type().Equals(MakeMapType(NumberType, NumberType)))

		m = m.Set(String("a"), String("a"))
		assert.Equal(m.Len(), uint64(n+1))
		assert.IsType(c, m.sequence())
		assert.True(m.Type().Equals(MakeMapType(MakeUnionType(NumberType, StringType), MakeUnionType(NumberType, StringType))))

		m = m.Remove(String("a"))
		assert.Equal(m.Len(), uint64(n))
		assert.IsType(c, m.sequence())
		assert.True(m.Type().Equals(MakeMapType(NumberType, NumberType)))
	}

	test(10, mapLeafSequence{})
	test(1000, orderedMetaSequence{})
}
func TestBuildWriteValueRequest(t *testing.T) {
	assert := assert.New(t)
	input1, input2 := "abc", "def"
	chnx := []chunks.Chunk{
		chunks.NewChunk([]byte(input1)),
		chunks.NewChunk([]byte(input2)),
	}

	hints := map[hash.Hash]struct{}{
		hash.Parse("sha1-0000000000000000000000000000000000000002"): struct{}{},
		hash.Parse("sha1-0000000000000000000000000000000000000003"): struct{}{},
	}
	compressed := buildWriteValueRequest(serializeChunks(chnx, assert), hints)
	gr := snappy.NewReader(compressed)

	count := 0
	for hint := range deserializeHints(gr) {
		count++
		_, present := hints[hint]
		assert.True(present)
	}
	assert.Equal(len(hints), count)

	chunkChan := make(chan *chunks.Chunk, 16)
	go chunks.DeserializeToChan(gr, chunkChan)
	for c := range chunkChan {
		assert.Equal(chnx[0].Hash(), c.Hash())
		chnx = chnx[1:]
	}
	assert.Empty(chnx)
}
Beispiel #4
0
func TestStringString(t *testing.T) {
	assert := assert.New(t)
	s1 := String("")
	s2 := String("foo")
	assert.Equal("", string(s1))
	assert.Equal("foo", string(s2))
}
Beispiel #5
0
func TestListDiffRemove5x100(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode.")
	}
	t.Parallel()
	assert := assert.New(t)
	nums1 := generateNumbersAsValues(5000)
	nums2 := generateNumbersAsValues(5000)
	for count := 5; count > 0; count-- {
		nums2 = spliceValues(nums2, (count-1)*1000, 100)
	}
	l1 := NewList(nums1...)
	l2 := NewList(nums2...)
	diff1 := l1.Diff(l2)
	diff2 := l2.Diff(l1)

	assert.Equal(len(diff1), len(diff2))
	diff2Expected := []Splice{
		Splice{0, 100, 0, 0},
		Splice{1000, 100, 0, 0},
		Splice{2000, 100, 0, 0},
		Splice{3000, 100, 0, 0},
		Splice{4000, 100, 0, 0},
	}
	assert.Equal(diff2Expected, diff2, "expected diff is wrong")
}
Beispiel #6
0
func TestSetTypeAfterMutations(t *testing.T) {
	assert := assert.New(t)

	smallTestChunks()
	defer normalProductionChunks()

	test := func(n int, c interface{}) {
		values := generateNumbersAsValues(n)

		s := NewSet(values...)
		assert.Equal(s.Len(), uint64(n))
		assert.IsType(c, s.sequence())
		assert.True(s.Type().Equals(MakeSetType(NumberType)))

		s = s.Insert(String("a"))
		assert.Equal(s.Len(), uint64(n+1))
		assert.IsType(c, s.sequence())
		assert.True(s.Type().Equals(MakeSetType(MakeUnionType(NumberType, StringType))))

		s = s.Remove(String("a"))
		assert.Equal(s.Len(), uint64(n))
		assert.IsType(c, s.sequence())
		assert.True(s.Type().Equals(MakeSetType(NumberType)))
	}

	test(10, setLeafSequence{})
	test(2000, orderedMetaSequence{})
}
func TestHandleGetRefs(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	input1, input2 := "abc", "def"
	chnx := []chunks.Chunk{
		chunks.NewChunk([]byte(input1)),
		chunks.NewChunk([]byte(input2)),
	}
	err := cs.PutMany(chnx)
	assert.NoError(err)

	body := strings.NewReader(fmt.Sprintf("ref=%s&ref=%s", chnx[0].Hash(), chnx[1].Hash()))

	w := httptest.NewRecorder()
	HandleGetRefs(w,
		&http.Request{Body: ioutil.NopCloser(body), Method: "POST", Header: http.Header{
			"Content-Type": {"application/x-www-form-urlencoded"},
		}},
		params{},
		cs,
	)

	if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
		chunkChan := make(chan *chunks.Chunk)
		go chunks.DeserializeToChan(w.Body, chunkChan)
		for c := range chunkChan {
			assert.Equal(chnx[0].Hash(), c.Hash())
			chnx = chnx[1:]
		}
		assert.Empty(chnx)
	}
}
Beispiel #8
0
func TestListDiffAdd5x5(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode.")
	}

	smallTestChunks()
	defer normalProductionChunks()

	assert := assert.New(t)
	nums1 := generateNumbersAsValues(5000)
	nums2 := generateNumbersAsValues(5000)
	for count := 5; count > 0; count-- {
		nums2 = spliceValues(nums2, (count-1)*1000, 0, Number(0), Number(1), Number(2), Number(3), Number(4))
	}
	l1 := NewList(nums1...)
	l2 := NewList(nums2...)

	diff1 := accumulateDiffSplices(l1, l2)
	diff2 := accumulateDiffSplices(l2, l1)

	assert.Equal(len(diff1), len(diff2))
	diff2Expected := []Splice{
		Splice{5, 0, 5, 5},
		Splice{1000, 0, 5, 1005},
		Splice{2000, 0, 5, 2010},
		Splice{3000, 0, 5, 3015},
		Splice{4000, 0, 5, 4020},
	}
	assert.Equal(diff2Expected, diff2, "expected diff is wrong")
}
Beispiel #9
0
func TestListDiffReverseWithLargerLimit(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode.")
	}

	smallTestChunks()
	defer normalProductionChunks()

	assert := assert.New(t)
	nums1 := generateNumbersAsValues(5000)
	nums2 := reverseValues(nums1)
	l1 := NewList(nums1...)
	l2 := NewList(nums2...)

	diff1 := accumulateDiffSplicesWithLimit(l1, l2, 27e6)
	diff2 := accumulateDiffSplicesWithLimit(l2, l1, 27e6)

	assert.Equal(len(diff2), len(diff1))
	diffExpected := []Splice{
		Splice{0, 2499, 2500, 0},
		Splice{2500, 2500, 2499, 2501},
	}
	assert.Equal(diffExpected, diff1, "expected diff is wrong")
	assert.Equal(diffExpected, diff2, "expected diff is wrong")
}
Beispiel #10
0
func TestBlobSplice(t *testing.T) {
	assert := assert.New(t)

	blob := NewEmptyBlob()
	buf := new(bytes.Buffer)

	blob = blob.Splice(0, 0, []byte("I'll do anything"))
	buf.Reset()
	buf.ReadFrom(blob.Reader())
	assert.Equal(buf.String(), "I'll do anything")

	blob = blob.Splice(16, 0, []byte(" for arv"))
	buf.Reset()
	buf.ReadFrom(blob.Reader())
	assert.Equal(buf.String(), "I'll do anything for arv")

	blob = blob.Splice(0, 0, []byte("Yes, "))
	buf.Reset()
	buf.ReadFrom(blob.Reader())
	assert.Equal(buf.String(), "Yes, I'll do anything for arv")

	blob = blob.Splice(5, 20, []byte("it's hard to satisfy"))
	buf.Reset()
	buf.ReadFrom(blob.Reader())
	assert.Equal(buf.String(), "Yes, it's hard to satisfy arv")
}
Beispiel #11
0
func TestIncrementalLoadList(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	vs := newLocalValueStore(cs)

	expected := NewList(testVals...)
	ref := vs.WriteValue(expected).TargetHash()

	actualVar := vs.ReadValue(ref)
	actual := actualVar.(List)

	expectedCount := cs.Reads
	assert.Equal(1, expectedCount)
	// There will be one read per chunk.
	chunkReads := make([]int, expected.Len())
	for i := uint64(0); i < expected.Len(); i++ {
		v := actual.Get(i)
		assert.True(expected.Get(i).Equals(v))

		expectedCount += isEncodedOutOfLine(v)
		assert.Equal(expectedCount+chunkReads[i], cs.Reads)

		// Do it again to make sure multiple derefs don't do multiple loads.
		v = actual.Get(i)
		assert.Equal(expectedCount+chunkReads[i], cs.Reads)
	}
}
Beispiel #12
0
func TestLDBObject(t *testing.T) {
	assert := assert.New(t)
	dir, err := ioutil.TempDir(os.TempDir(), "")
	assert.NoError(err)
	ldbpath := path.Join(dir, "xx-yy")
	dsId := "dsId"

	cs1 := chunks.NewLevelDBStoreUseFlags(ldbpath, "")
	store1 := datas.NewDatabase(cs1)
	dataset1 := dataset.NewDataset(store1, dsId)
	s1 := types.String("Commit Value")
	r1 := store1.WriteValue(s1)
	_, err = dataset1.Commit(r1)
	assert.NoError(err)
	store1.Close()

	spec2 := fmt.Sprintf("ldb:%s::%s", ldbpath, dsId)
	assert.NoError(err)
	sp1, err := ParseDatasetSpec(spec2)
	assert.NoError(err)
	dataset2, err := sp1.Dataset()
	assert.NoError(err)
	r2 := dataset2.HeadValue()
	s2 := r2.(types.Ref).TargetValue(dataset2.Database())
	assert.Equal(s1, s2)
	dataset2.Database().Close()

	spec3 := fmt.Sprintf("ldb:%s::%s", ldbpath, s1.Hash().String())
	sp3, err := ParsePathSpec(spec3)
	database, v3, err := sp3.Value()
	assert.Equal(s1, v3)
	database.Close()
}
func TestHandleWriteValueBackpressure(t *testing.T) {
	assert := assert.New(t)
	cs := &backpressureCS{ChunkStore: chunks.NewMemoryStore()}
	ds := NewDatabase(cs)

	l := types.NewList(
		ds.WriteValue(types.Bool(true)),
		ds.WriteValue(types.Bool(false)),
	)
	ds.WriteValue(l)

	hint := l.Hash()
	newItem := types.NewEmptyBlob()
	itemChunk := types.EncodeValue(newItem, nil)
	l2 := l.Insert(1, types.NewRef(newItem))
	listChunk := types.EncodeValue(l2, nil)

	body := &bytes.Buffer{}
	serializeHints(body, map[hash.Hash]struct{}{hint: struct{}{}})
	sz := chunks.NewSerializer(body)
	sz.Put(itemChunk)
	sz.Put(listChunk)
	sz.Close()

	w := httptest.NewRecorder()
	HandleWriteValue(w, &http.Request{Body: ioutil.NopCloser(body), Method: "POST"}, params{}, cs)

	if assert.Equal(httpStatusTooManyRequests, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
		hashes := deserializeHashes(w.Body)
		assert.Len(hashes, 1)
		assert.Equal(l2.Hash(), hashes[0])
	}
}
Beispiel #14
0
func SkipTestIncrementalAddRef(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	vs := newLocalValueStore(cs)

	expectedItem := Number(42)
	ref := vs.WriteValue(expectedItem)

	expected := NewList(ref)
	ref = vs.WriteValue(expected)
	actualVar := vs.ReadValue(ref.TargetHash())

	assert.Equal(1, cs.Reads)
	assert.True(expected.Equals(actualVar))

	actual := actualVar.(List)
	actualItem := actual.Get(0)
	assert.Equal(2, cs.Reads)
	assert.True(expectedItem.Equals(actualItem))

	// do it again to make sure caching works.
	actualItem = actual.Get(0)
	assert.Equal(2, cs.Reads)
	assert.True(expectedItem.Equals(actualItem))
}
Beispiel #15
0
func TestHeadValueFunctions(t *testing.T) {
	assert := assert.New(t)

	id1 := "testdataset"
	id2 := "otherdataset"
	cs := chunks.NewMemoryStore()

	ds1 := newDS(id1, cs)

	// ds1: |a|
	a := types.String("a")
	ds1, err := ds1.CommitValue(a)
	assert.NoError(err)

	hv := ds1.Head().Get(datas.ValueField)
	assert.Equal(a, hv)
	assert.Equal(a, ds1.HeadValue())

	hv, ok := ds1.MaybeHeadValue()
	assert.True(ok)
	assert.Equal(a, hv)

	ds2 := newDS(id2, cs)
	assert.Panics(func() {
		ds2.HeadValue()
	})
	_, ok = ds2.MaybeHeadValue()
	assert.False(ok)
}
Beispiel #16
0
func TestConstructQueryString(t *testing.T) {
	assert := assert.New(t)
	prefix := "TestConstructQueryString"

	d1, e1 := ioutil.TempDir(os.TempDir(), prefix)
	defer os.RemoveAll(d1)
	d2, e2 := ioutil.TempDir(os.TempDir(), prefix)
	defer os.RemoveAll(d2)

	assert.NoError(e1)
	assert.NoError(e2)

	qs, stores := constructQueryString([]string{
		"foo=bar",
		"store1=ldb:" + d1,
		"store2=ldb:" + d2,
		"store3=ldb:" + d1,
		"hello=world",
	})

	assert.Equal(5, len(qs))
	assert.Equal("bar", qs.Get("foo"))
	assert.True(strings.HasPrefix(qs.Get("store1"), dsPathPrefix))
	assert.True(strings.HasPrefix(qs.Get("store2"), dsPathPrefix))
	assert.True(strings.HasPrefix(qs.Get("store3"), dsPathPrefix))
	assert.Equal(qs.Get("store1"), qs.Get("store3"))
	assert.NotEqual(qs.Get("store1"), qs.Get("store2"))
	assert.Equal(2, len(stores))
}
Beispiel #17
0
// Note: This test is asserting that findCommon correctly separates refs which are exclusive to |taller| from those which are |common|.
func TestFindCommon(t *testing.T) {
	taller := &types.RefByHeight{}
	shorter := &types.RefByHeight{}

	for i := 0; i < 50; i++ {
		shorter.PushBack(types.NewRef(types.Number(i)))
	}

	for i := 50; i < 250; i++ {
		shorter.PushBack(types.NewRef(types.Number(i)))
		taller.PushBack(types.NewRef(types.Number(i)))
	}

	for i := 250; i < 275; i++ {
		taller.PushBack(types.NewRef(types.Number(i)))
	}

	sort.Sort(shorter)
	sort.Sort(taller)

	tallRefs, comRefs := findCommon(taller, shorter, 1)
	assert.Equal(t, 25, len(tallRefs))
	assert.Equal(t, 200, len(comRefs))
	assert.Equal(t, 0, len(*taller))
	assert.Equal(t, 50, len(*shorter))
}
Beispiel #18
0
func TestListTypeAfterMutations(t *testing.T) {
	smallTestChunks()
	defer normalProductionChunks()

	assert := assert.New(t)

	test := func(n int, c interface{}) {
		values := generateNumbersAsValues(n)

		l := NewList(values...)
		assert.Equal(l.Len(), uint64(n))
		assert.IsType(c, l.sequence())
		assert.True(l.Type().Equals(MakeListType(NumberType)))

		l = l.Append(String("a"))
		assert.Equal(l.Len(), uint64(n+1))
		assert.IsType(c, l.sequence())
		assert.True(l.Type().Equals(MakeListType(MakeUnionType(NumberType, StringType))))

		l = l.Splice(l.Len()-1, 1)
		assert.Equal(l.Len(), uint64(n))
		assert.IsType(c, l.sequence())
		assert.True(l.Type().Equals(MakeListType(NumberType)))
	}

	test(15, listLeafSequence{})
	test(1500, indexedMetaSequence{})
}
func TestHandlePostRoot(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	vs := types.NewValueStore(types.NewBatchStoreAdaptor(cs))

	commit := NewCommit(types.String("head"), types.NewSet(), types.NewStruct("Meta", types.StructData{}))
	newHead := types.NewMap(types.String("dataset1"), vs.WriteValue(commit))
	chnx := []chunks.Chunk{
		chunks.NewChunk([]byte("abc")),
		types.EncodeValue(newHead, nil),
	}
	err := cs.PutMany(chnx)
	assert.NoError(err)

	// First attempt should fail, as 'last' won't match.
	u := &url.URL{}
	queryParams := url.Values{}
	queryParams.Add("last", chnx[0].Hash().String())
	queryParams.Add("current", chnx[1].Hash().String())
	u.RawQuery = queryParams.Encode()
	url := u.String()

	w := httptest.NewRecorder()
	HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
	assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))

	// Now, update the root manually to 'last' and try again.
	assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{}))
	w = httptest.NewRecorder()
	HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
	assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
Beispiel #20
0
func TestListRemoveRanges(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping test in short mode.")
	}
	assert := assert.New(t)

	smallTestChunks()
	defer normalProductionChunks()

	testList := getTestList()
	whole := testList.toList()

	// Compare list equality. Increment by 256 (16^2) because each iteration requires building a new list, which is slow.
	for incr, i := 256, 0; i < len(testList)-incr; i += incr {
		for window := 1; window <= incr; window *= 16 {
			testListPart := testList.Remove(i, i+window)
			expected := testListPart.toList()
			actual := whole.Remove(uint64(i), uint64(i+window))
			assert.Equal(expected.Len(), actual.Len())
			assert.True(expected.Equals(actual))
		}
	}

	// Compare list length, which doesn't require building a new list every iteration, so the increment can be smaller.
	for incr, i := 10, 0; i < len(testList)-incr; i += incr {
		assert.Equal(len(testList)-incr, int(whole.Remove(uint64(i), uint64(i+incr)).Len()))
	}
}
func TestHandlePostRoot(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	input1, input2 := "abc", "def"
	chnx := []chunks.Chunk{
		chunks.NewChunk([]byte(input1)),
		chunks.NewChunk([]byte(input2)),
	}
	err := cs.PutMany(chnx)
	assert.NoError(err)

	// First attempt should fail, as 'last' won't match.
	u := &url.URL{}
	queryParams := url.Values{}
	queryParams.Add("last", chnx[0].Hash().String())
	queryParams.Add("current", chnx[1].Hash().String())
	u.RawQuery = queryParams.Encode()

	w := httptest.NewRecorder()
	HandleRootPost(w, &http.Request{URL: u, Method: "POST"}, params{}, cs)
	assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))

	// Now, update the root manually to 'last' and try again.
	assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{}))
	w = httptest.NewRecorder()
	HandleRootPost(w, &http.Request{URL: u, Method: "POST"}, params{}, cs)
	assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
func TestWriteValue(t *testing.T) {
	assert := assert.New(t)
	factory := chunks.NewMemoryStoreFactory()
	defer factory.Shutter()

	router = setupWebServer(factory)
	defer func() { router = nil }()

	testString := "Now, what?"
	authKey = "anauthkeyvalue"

	w := httptest.NewRecorder()
	r, err := newRequest("GET", dbName+constants.RootPath, nil)
	assert.NoError(err)
	router.ServeHTTP(w, r)
	lastRoot := w.Body
	assert.Equal(http.StatusOK, w.Code)

	tval := types.Bool(true)
	wval := types.String(testString)
	chunk1 := types.EncodeValue(tval, nil)
	chunk2 := types.EncodeValue(wval, nil)
	refList := types.NewList(types.NewRef(tval), types.NewRef(wval))
	chunk3 := types.EncodeValue(refList, nil)

	body := &bytes.Buffer{}
	// we would use this func, but it's private so use next line instead: serializeHints(body, map[ref.Ref]struct{}{hint: struct{}{}})
	err = binary.Write(body, binary.BigEndian, uint32(0))
	assert.NoError(err)

	chunks.Serialize(chunk1, body)
	chunks.Serialize(chunk2, body)
	chunks.Serialize(chunk3, body)

	w = httptest.NewRecorder()
	r, err = newRequest("POST", dbName+constants.WriteValuePath+"?access_token="+authKey, ioutil.NopCloser(body))
	assert.NoError(err)
	router.ServeHTTP(w, r)
	assert.Equal(http.StatusCreated, w.Code)

	w = httptest.NewRecorder()
	args := fmt.Sprintf("&last=%s&current=%s", lastRoot, types.NewRef(refList).TargetHash())
	r, _ = newRequest("POST", dbName+constants.RootPath+"?access_token="+authKey+args, ioutil.NopCloser(body))
	router.ServeHTTP(w, r)
	assert.Equal(http.StatusOK, w.Code)

	whash := wval.Hash()
	hints := map[hash.Hash]struct{}{whash: struct{}{}}
	rdr := buildGetRefsRequestBody(hints)
	r, _ = newRequest("POST", dbName+constants.GetRefsPath, rdr)
	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	router.ServeHTTP(w, r)
	assert.Equal(http.StatusOK, w.Code)

	ms := chunks.NewMemoryStore()
	chunks.Deserialize(w.Body, ms, nil)
	v := types.DecodeValue(ms.Get(whash), datas.NewDatabase(ms))
	assert.Equal(testString, string(v.(types.String)))
}
Beispiel #23
0
func TestStructDiff(t *testing.T) {
	assert := assert.New(t)

	assertDiff := func(expect []string, s1, s2 Struct) {
		actual := StructDiff(s1, s2)
		assert.Equal(len(expect), len(actual))
		for i, _ := range actual {
			assert.Equal(expect[i], actual[i])
		}
	}

	s1 := NewStruct("", map[string]Value{"a": Bool(true), "b": String("hi"), "c": Number(4)})

	assertDiff([]string{}, s1,
		NewStruct("", map[string]Value{"a": Bool(true), "b": String("hi"), "c": Number(4)}))

	assertDiff([]string{"a", "b"}, s1,
		NewStruct("", map[string]Value{"a": Bool(false), "b": String("bye"), "c": Number(4)}))

	assertDiff([]string{"b", "c"}, s1,
		NewStruct("", map[string]Value{"a": Bool(true), "b": String("bye"), "c": Number(5)}))

	assertDiff([]string{"a", "c"}, s1,
		NewStruct("", map[string]Value{"a": Bool(false), "b": String("hi"), "c": Number(10)}))

	s2 := NewStruct("", map[string]Value{
		"a": NewList(Number(0), Number(1)),
		"b": NewMap(String("foo"), Bool(false), String("bar"), Bool(true)),
		"c": NewSet(Number(0), Number(1), String("foo")),
	})

	assertDiff([]string{}, s2,
		NewStruct("", map[string]Value{
			"a": NewList(Number(0), Number(1)),
			"b": NewMap(String("foo"), Bool(false), String("bar"), Bool(true)),
			"c": NewSet(Number(0), Number(1), String("foo")),
		}))

	assertDiff([]string{"a", "b"}, s2,
		NewStruct("", map[string]Value{
			"a": NewList(Number(1), Number(1)),
			"b": NewMap(String("foo"), Bool(true), String("bar"), Bool(true)),
			"c": NewSet(Number(0), Number(1), String("foo")),
		}))

	assertDiff([]string{"a", "c"}, s2,
		NewStruct("", map[string]Value{
			"a": NewList(Number(0)),
			"b": NewMap(String("foo"), Bool(false), String("bar"), Bool(true)),
			"c": NewSet(Number(0), Number(2), String("foo")),
		}))

	assertDiff([]string{"b", "c"}, s2,
		NewStruct("", map[string]Value{
			"a": NewList(Number(0), Number(1)),
			"b": NewMap(String("boo"), Bool(false), String("bar"), Bool(true)),
			"c": NewSet(Number(0), Number(1), String("bar")),
		}))
}
Beispiel #24
0
func assertAttr(s *fuseTestSuite, fs pathfs.FileSystem, path string, mode uint32, size uint64) {
	attr, code := fs.GetAttr(path, nil)
	assert.Equal(s.T(), fuse.OK, code)
	if code == fuse.OK {
		assert.Equal(s.T(), mode, attr.Mode)
		assert.Equal(s.T(), size, attr.Size)
	}
}
Beispiel #25
0
func TestSuiteGetters(t *testing.T) {
	suite := new(SuiteTester)
	suite.SetT(t)
	assert.NotNil(t, suite.Assert())
	assert.Equal(t, suite.Assertions, suite.Assert())
	assert.NotNil(t, suite.Require())
	assert.Equal(t, suite.require, suite.Require())
}
Beispiel #26
0
func TestUnwrap(t *testing.T) {
	assert := assert.New(t)

	err := errors.New("test")
	we := wrappedError{"test msg", err}
	assert.Equal(err, Unwrap(err))
	assert.Equal(err, Unwrap(we))
}
Beispiel #27
0
func TestSetFirstNNumbers(t *testing.T) {
	assert := assert.New(t)

	nums := generateNumbersAsValues(testSetSize)
	s := NewSet(nums...)
	assert.Equal("sha1-1fc97c4e369770b643e013569c68687765601514", s.Hash().String())
	assert.Equal(deriveCollectionHeight(s), getRefHeightOfCollection(s))
}
Beispiel #28
0
func TestSetFirstNNumbers(t *testing.T) {
	assert := assert.New(t)

	nums := generateNumbersAsValues(testSetSize)
	s := NewSet(nums...)
	assert.Equal("hius38tca4nfd5lveqe3h905ass99uq2", s.Hash().String())
	assert.Equal(deriveCollectionHeight(s), getRefHeightOfCollection(s))
}
Beispiel #29
0
func Test_Mock_On(t *testing.T) {

	// make a test impl object
	var mockedService = new(TestExampleImplementation)

	c := mockedService.On("TheExampleMethod")
	assert.Equal(t, []*Call{c}, mockedService.ExpectedCalls)
	assert.Equal(t, "TheExampleMethod", c.Method)
}
Beispiel #30
0
/*
	Arguments helper methods
*/
func Test_Arguments_Get(t *testing.T) {

	var args = Arguments([]interface{}{"string", 123, true})

	assert.Equal(t, "string", args.Get(0).(string))
	assert.Equal(t, 123, args.Get(1).(int))
	assert.Equal(t, true, args.Get(2).(bool))

}