Esempio n. 1
1
func TestJsonHelperGobEncoding(t *testing.T) {
	raw := `{"testing": 123,"name":"bob & more"}`
	reader := strings.NewReader(raw)
	jh, err := NewJsonHelperReader(reader)
	assert.Tf(t, err == nil, "Unexpected error decoding gob: %s", err)
	assert.Tf(t, jh.Int("testing") == 123, "Unexpected value in gob: %d", jh.Int("testing"))
	var buf bytes.Buffer
	err = gob.NewEncoder(&buf).Encode(&jh)
	assert.T(t, err == nil, err)

	var jhNew JsonHelper
	err = gob.NewDecoder(&buf).Decode(&jhNew)
	assert.T(t, err == nil, err)
	assert.Tf(t, jhNew.Int("testing") == 123, "Unexpected value in gob: %d", jhNew.Int("testing"))
	assert.Tf(t, jhNew.String("name") == "bob & more", "Unexpected value in gob: %d", jhNew.String("name"))

	buf2 := bytes.Buffer{}
	gt := GobTest{"Hello", jh}
	err = gob.NewEncoder(&buf2).Encode(&gt)
	assert.T(t, err == nil, err)

	var gt2 GobTest
	err = gob.NewDecoder(&buf2).Decode(&gt2)
	assert.T(t, err == nil, err)
	assert.Tf(t, gt2.Name == "Hello", "Unexpected value in gob: %d", gt2.Name)
	assert.Tf(t, gt2.Data.Int("testing") == 123, "Unexpected value in gob: %d", gt2.Data.Int("testing"))
	assert.Tf(t, gt2.Data.String("name") == "bob & more", "Unexpected value in gob: %d", gt2.Data.String("name"))
}
Esempio n. 2
0
func TestExecHaving(t *testing.T) {
	sqlText := `
		select 
	        user_id, count(user_id) AS order_ct
	    FROM orders
	    GROUP BY user_id
	    HAVING order_ct > 1
	`
	ctx := td.TestContext(sqlText)
	job, err := exec.BuildSqlJob(ctx)
	assert.Tf(t, err == nil, "no error %v", err)

	msgs := make([]schema.Message, 0)
	resultWriter := exec.NewResultBuffer(ctx, &msgs)
	job.RootTask.Add(resultWriter)

	err = job.Setup()
	assert.T(t, err == nil)
	err = job.Run()
	time.Sleep(time.Millisecond * 10)
	assert.Tf(t, err == nil, "no error %v", err)
	assert.Tf(t, len(msgs) == 1, "should have filtered HAVING orders into 1 users %v", len(msgs))
	u.Debugf("msg: %#v", msgs[0])
	row := msgs[0].(*datasource.SqlDriverMessageMap).Values()
	u.Debugf("row: %#v", row)
	assert.Tf(t, len(row) == 2, "expects 2 cols but got %v", len(row))
	assert.T(t, row[0] == "9Ip1aKbeZe2njCDM")
	// I really don't like this float behavior?
	assert.Tf(t, int(row[1].(int64)) == 2, "expected 2 orders for %v", row)
}
Esempio n. 3
0
func TestDoozerWaitSimple(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenUDP(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", "", "", nil, u, l, nil, 1e9, 2e9, 3e9, 101)

	cl := dial(l.Addr().String())
	var rev int64 = 1

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	ev, err := cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())
	rev = ev.Rev + 1

	cl.Set("/test/fun", store.Clobber, []byte("house"))
	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())
	rev = ev.Rev + 1

	cl.Del("/test/foo", store.Clobber)
	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.T(t, ev.IsDel())
}
Esempio n. 4
0
func DoTestStoreRelPath(t *testing.T, repo fs.NodeRepo) {
	tg := treegen.New()
	treeSpec := tg.D("foo", tg.F("bar", tg.B(42, 65537)))

	path := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(path)

	store, err := fs.NewLocalStore(path, repo)
	assert.T(t, err == nil)

	relFoo := store.RelPath(filepath.Join(path, "foo"))
	assert.Equalf(t, "foo", relFoo, "'%v': not a foo", relFoo)

	// Relocate bar
	newBar, err := store.Relocate(filepath.Join(filepath.Join(path, "foo"), "bar"))
	assert.T(t, err == nil)

	// new bar's parent should still be foo
	newBarParent, _ := filepath.Split(newBar)
	newBarParent = strings.TrimRight(newBarParent, "/\\")

	// old bar should not exist
	_, err = os.Stat(filepath.Join(filepath.Join(path, "foo"), "bar"))
	assert.T(t, err != nil)

	foobar := filepath.Join("foo", "bar")
	assert.Equal(t, newBar, store.Resolve(foobar), "reloc path %s != resolve foo/bar %s",
		newBar, store.Resolve(foobar))
}
Esempio n. 5
0
func TestDoozerWalk(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := dial(l.Addr().String())

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	rev, err := cl.Rev()
	if err != nil {
		panic(err)
	}

	info, err := cl.Walk("/test/**", rev, 0, -1)
	assert.Equal(t, nil, err)
	assert.Equal(t, 2, len(info))

	assert.Equal(t, "/test/foo", info[0].Path)
	assert.Equal(t, "bar", string(info[0].Body))
	assert.T(t, info[0].IsSet())

	assert.Equal(t, "/test/fun", info[1].Path)
	assert.Equal(t, "house", string(info[1].Body))
	assert.T(t, info[1].IsSet())
}
Esempio n. 6
0
func TestAuthorizationsService_All(t *testing.T) {
	setup()
	defer tearDown()

	mux.HandleFunc("/authorizations", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "GET")
		respondWithJSON(w, loadFixture("authorizations.json"))
	})

	url, err := AuthorizationsURL.Expand(nil)
	assert.Equal(t, nil, err)

	auths, result := client.Authorizations(url).All()
	assert.T(t, !result.HasError())

	firstAuth := auths[0]
	assert.Equal(t, 1, firstAuth.ID)
	assert.Equal(t, "https://api.github.com/authorizations/1", firstAuth.URL)
	assert.Equal(t, "456", firstAuth.Token)
	assert.Equal(t, "", firstAuth.Note)
	assert.Equal(t, "", firstAuth.NoteURL)
	assert.Equal(t, "2012-11-16 01:05:51 +0000 UTC", firstAuth.CreatedAt.String())
	assert.Equal(t, "2013-08-21 03:29:51 +0000 UTC", firstAuth.UpdatedAt.String())

	app := App{ClientID: "123", URL: "http://localhost:8080", Name: "Test"}
	assert.Equal(t, app, firstAuth.App)

	assert.Equal(t, 2, len(firstAuth.Scopes))
	scopes := []string{"repo", "user"}
	assert.T(t, reflect.DeepEqual(firstAuth.Scopes, scopes))
}
Esempio n. 7
0
func TestModelReload(t *testing.T) {
	// Preparations
	client := setupConnection(t)
	assert.T(t, client != nil)

	// Create a new "DocumentModel" and save it
	doc := DocumentModel{FieldS: "text", FieldF: 1.2, FieldB: true}
	err := client.New("testmodel.go", "TestModelKey", &doc)
	assert.T(t, err == nil)
	err = doc.Save()
	assert.T(t, err == nil)

	doc2 := DocumentModel{FieldS: "text22", FieldF: 1.4, FieldB: true}
	err = client.New("testmodel.go", "TestModelKey", &doc2)
	err = doc2.Save()
	assert.T(t, err == nil)

	vclock := string(doc.robject.Vclock)
	err = (&doc).Reload()
	assert.T(t, err == nil)
	assert.T(t, string(doc.robject.Vclock) != vclock)
	assert.T(t, string(doc.robject.Vclock) == string(doc2.robject.Vclock))
	assert.T(t, doc.FieldS == doc2.FieldS)
	assert.T(t, doc.FieldF == doc2.FieldF)
	assert.T(t, doc.FieldB == doc2.FieldB)
}
func TestRepositoresService_CreateFork(t *testing.T) {
	setup()
	defer tearDown()

	mux.HandleFunc("/repos/jingweno/octokat/forks", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "POST")
		testBody(t, r, "{\"organization\":\"github\"}\n")
		respondWithJSON(w, loadFixture("create_repository.json"))
	})

	reposService, err := client.Repositories(&ForksURL, M{"owner": "jingweno", "repo": "octokat"})
	assert.Equal(t, nil, err)

	repo, result := reposService.Create(M{"organization": "github"})

	assert.T(t, !result.HasError())
	assert.Equal(t, 1296269, repo.ID)
	assert.Equal(t, "Hello-World", repo.Name)
	assert.Equal(t, "octocat/Hello-World", repo.FullName)
	assert.Equal(t, "This is your first repo", repo.Description)
	assert.T(t, !repo.Private)
	assert.T(t, repo.Fork)
	assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World", repo.URL)
	assert.Equal(t, "https://github.com/octocat/Hello-World", repo.HTMLURL)
	assert.Equal(t, "https://github.com/octocat/Hello-World.git", repo.CloneURL)
	assert.Equal(t, "git://github.com/octocat/Hello-World.git", repo.GitURL)
	assert.Equal(t, "[email protected]:octocat/Hello-World.git", repo.SSHURL)
	assert.Equal(t, "master", repo.MasterBranch)
}
Esempio n. 9
0
func TestDoozerWalk(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	w, err := cl.Walk("/test/**", nil, nil, nil)
	assert.Equal(t, nil, err, err)

	ev := <-w.C
	assert.NotEqual(t, (*doozer.Event)(nil), ev)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, "bar", string(ev.Body))
	assert.T(t, ev.IsSet())

	ev = <-w.C
	assert.NotEqual(t, (*doozer.Event)(nil), ev)
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, "house", string(ev.Body))
	assert.T(t, ev.IsSet())

	ev = <-w.C
	assert.Tf(t, closed(w.C), "got %v", ev)
}
Esempio n. 10
0
func TestDoozerWatchWithRev(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	// Create some history
	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	// Ask doozer for the history
	w, err := cl.Watch("/test/**", 1)
	assert.Equal(t, nil, err, err)
	defer w.Cancel()

	ev := <-w.C
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())

	ev = <-w.C
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())
}
Esempio n. 11
0
func TestDoozerWatchSimple(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := doozer.New("foo", l.Addr().String())

	w, err := cl.Watch("/test/**", 0)
	assert.Equal(t, nil, err, err)
	defer w.Cancel()

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	ev := <-w.C
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())

	cl.Set("/test/fun", store.Clobber, []byte("house"))
	ev = <-w.C
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())

	cl.Del("/test/foo", store.Clobber)
	ev = <-w.C
	assert.Equal(t, "/test/foo", ev.Path)
	assert.T(t, ev.IsDel())

	w.Cancel()
	ev = <-w.C
	assert.Tf(t, closed(w.C), "got %v", ev)
}
Esempio n. 12
0
func TestDirDescent(t *testing.T) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.F("baobab", tg.B(91, 65537)),
		tg.D("bar",
			tg.D("aleph",
				tg.F("a", tg.B(42, 65537)))),
		tg.F("bar3003", tg.B(777, 65537)))

	path := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(path)

	dir, err := IndexDir(path)
	assert.T(t, err == nil)

	for _, fpath := range []string{
		filepath.Join("foo", "baobab"),
		filepath.Join("foo", "bar", "aleph", "a"),
		filepath.Join("foo", "bar3003")} {
		node, found := dir.Resolve(fpath)
		assert.Tf(t, found, "not found: %s", fpath)
		_, isFile := node.(*File)
		assert.T(t, isFile)
	}

	node, found := dir.Resolve(filepath.Join("foo", "bar"))
	assert.T(t, found)
	_, isDir := node.(*Dir)
	assert.T(t, isDir)
}
Esempio n. 13
0
func TestOpenCloseStore(t *testing.T) {

	go func() {
		log.Debugf("Error creating http server %v\n", http.ListenAndServe("localhost:6060", nil))
	}()
	for i := 0; i < 100; i++ {
		store, err := OpenStore("test.db")
		assert.T(t, err == nil, err)
		init := store.getWritePointer()
		acks := make(chan bool)
		for i := 0; i < 100; i++ {
			store.eventsInChannel() <- &EventIn{event: &Event{Channel: "test", Body: []byte("BODY-TestOpenCloseStore")}, saved: acks}
			<-acks
		}
		curr := store.getWritePointer()
		assert.Equal(t, init+100, curr)
		store.Close()

		store, err = OpenStore("test.db")
		assert.T(t, err == nil, err)
		init = store.getWritePointer()
		assert.Equal(t, init, curr)
		store.Close()
	}
}
Esempio n. 14
0
func TestSerialize(t *testing.T) {
	for i := 1; i < 100000; i++ {
		read, err := readSequence(writeSequence(int64(i)))
		assert.T(t, err == nil, err)
		assert.T(t, read == int64(i))
	}
}
Esempio n. 15
0
func TestSession(t *testing.T) {
	st := store.New()
	defer close(st.Ops)
	fp := &test.FakeProposer{Store: st}
	go Clean(st, fp)

	ch := make(chan store.Event, 100)
	go func(c <-chan store.Event) {
		for e := range c {
			ch <- e
		}
		close(ch)
	}(st.Watch("/session/*"))

	// check-in with less than a nanosecond to live
	body := strconv.Itoa64(time.Nanoseconds() + 1)
	fp.Propose(store.MustEncodeSet("/session/a", body, store.Clobber))

	// Throw away the set
	assert.T(t, (<-ch).IsSet())

	ev := <-ch
	assert.T(t, ev.IsDel())
	assert.Equal(t, "/session/a", ev.Path)
}
Esempio n. 16
0
// Should create a new Spotify Object.
func TestGet(t *testing.T) {

	result, err := spotify.Get("albums/%s", nil, "0sNOF9WDwhWunNAHPD3Baj")
	assert.T(t, result != nil, "Shouldnt be null")
	assert.T(t, err == nil, "Should be null")

}
Esempio n. 17
0
func TestRepositoresService_Get(t *testing.T) {
	setup()
	defer tearDown()

	mux.HandleFunc("/repos/jingweno/octokat", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "GET")
		respondWithJSON(w, loadFixture("repository.json"))
	})

	reposService, err := client.Repositories(&RepositoryURL, M{"owner": "jingweno", "repo": "octokat"})
	assert.Equal(t, nil, err)

	repo, result := reposService.Get()

	assert.T(t, !result.HasError())
	assert.Equal(t, 10575811, repo.ID)
	assert.Equal(t, "octokat", repo.Name)
	assert.Equal(t, "jingweno/octokat", repo.FullName)
	assert.T(t, !repo.Private)
	assert.T(t, !repo.Fork)
	assert.Equal(t, "https://api.github.com/repos/jingweno/octokat", repo.URL)
	assert.Equal(t, "https://github.com/jingweno/octokat", repo.HTMLURL)
	assert.Equal(t, "https://github.com/jingweno/octokat.git", repo.CloneURL)
	assert.Equal(t, "git://github.com/jingweno/octokat.git", repo.GitURL)
	assert.Equal(t, "[email protected]:jingweno/octokat.git", repo.SSHURL)
	assert.Equal(t, "master", repo.MasterBranch)
}
Esempio n. 18
0
func TestDoozerWaitSimple(t *testing.T) {
	var (
		l  = mustListen()
		st = store.New(store.DefaultInitialRev)
	)
	defer l.Close()

	go Main("a", "X", nil, l, nil, st, 1e6)

	cl := dial(l.Addr().String())
	var rev int64 = 1

	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	ev, err := cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())
	rev = ev.Rev + 1

	cl.Set("/test/fun", store.Clobber, []byte("house"))
	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())
	rev = ev.Rev + 1

	cl.Del("/test/foo", store.Clobber)
	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.T(t, ev.IsDel())
}
Esempio n. 19
0
func TestInclude(t *testing.T) {
	t.Parallel()

	e1 := datasource.NewContextSimpleNative(map[string]interface{}{"x": 6, "y": "1"})
	e2 := datasource.NewContextSimpleNative(map[string]interface{}{"x": 4, "y": "1"})

	q, err := rel.ParseFilterQL("FILTER AND (x < 9000, INCLUDE test)")
	assert.Equal(t, nil, err)

	filterVm := NewFilterVm(includer{})

	{
		match, err := filterVm.Matches(e1, q)
		assert.Equal(t, nil, err)
		assert.T(t, match)
	}

	{
		match, err := filterVm.Matches(e2, q)
		assert.Equal(t, nil, err)
		assert.T(t, !match)
	}

	// Matches should return an error when the query includes an invalid INCLUDE
	{
		q, err := rel.ParseFilterQL("FILTER AND (x < 9000, INCLUDE shouldfail)")
		assert.Equal(t, nil, err)
		_, err = filterVm.Matches(e1, q)
		assert.NotEqual(t, nil, err)
	}
}
Esempio n. 20
0
// Should make a new Request
func TestRequest(t *testing.T) {

	result, error := shop.Request("GET", "products", nil)

	assert.T(t, error == nil, "should be null")
	assert.T(t, result != nil, "shouldnt be null")
}
Esempio n. 21
0
func TestStoreIterator(t *testing.T) {
	temp := NewStore("./test3.db", true)
	temp.Put(NewRecord([]byte("foo"), "testqueue"))
	temp.Put(NewRecord([]byte("bar"), "testqueue"))
	temp.Close()

	store := NewStore("./test3.db", true)
	defer store.Drop()

	it := store.Iterator()

	assert.T(t, it.Valid())

	one := it.Record()
	assert.Equal(t, one.id, 1)
	assert.Equal(t, one.Value, []byte("foo"))
	assert.Equal(t, one.Queue, "testqueue")

	it.Next()

	two := it.Record()
	assert.Equal(t, two.id, 2)
	assert.Equal(t, two.Value, []byte("bar"))
	assert.Equal(t, two.Queue, "testqueue")

	it.Next()

	assert.T(t, !it.Valid())
}
Esempio n. 22
0
func TestUrlGenerationNoPercolate(t *testing.T) {
	expectedUrl := "/Index/Type/Id?op_type=create&parent=Parent&refresh=true&routing=Routing&timeout=Timeout&timestamp=TimeStamp&ttl=10&version=1"
	url, err := GetIndexUrl("Index", "Type", "Id", "Parent", 1, "create", "Routing", "TimeStamp", 10, "", "Timeout", true)
	assert.T(t, err == nil, t, "err was not nil")
	assert.T(t, url == expectedUrl,
		fmt.Sprintf("TestUrlGenerationNoPercolate Should get %s, instead got %s", expectedUrl, url))
}
Esempio n. 23
0
func TestAuthorizationsService_Create(t *testing.T) {
	setup()
	defer tearDown()

	params := AuthorizationParams{Scopes: []string{"public_repo"}}

	mux.HandleFunc("/authorizations", func(w http.ResponseWriter, r *http.Request) {
		var authParams AuthorizationParams
		json.NewDecoder(r.Body).Decode(&authParams)
		assert.T(t, reflect.DeepEqual(authParams, params))

		testMethod(t, r, "POST")
		respondWithJSON(w, loadFixture("create_authorization.json"))
	})

	url, err := AuthorizationsURL.Expand(nil)
	assert.Equal(t, nil, err)

	auth, _ := client.Authorizations(url).Create(params)

	assert.Equal(t, 3844190, auth.ID)
	assert.Equal(t, "https://api.github.com/authorizations/3844190", auth.URL)
	assert.Equal(t, "123", auth.Token)
	assert.Equal(t, "", auth.Note)
	assert.Equal(t, "", auth.NoteURL)
	assert.Equal(t, "2013-09-28 18:44:39 +0000 UTC", auth.CreatedAt.String())
	assert.Equal(t, "2013-09-28 18:44:39 +0000 UTC", auth.UpdatedAt.String())

	app := App{ClientID: "00000000000000000000", URL: "http://developer.github.com/v3/oauth/#oauth-authorizations-api", Name: "GitHub API"}
	assert.Equal(t, app, auth.App)

	assert.Equal(t, 1, len(auth.Scopes))
	scopes := []string{"public_repo"}
	assert.T(t, reflect.DeepEqual(auth.Scopes, scopes))
}
Esempio n. 24
0
func TestRegexpFunction(t *testing.T) {
	db := open(t)
	defer checkClose(db, t)
	err := db.CreateScalarFunction("regexp", 2, true, nil, re, reDestroy)
	checkNoError(t, err, "couldn't create function: %s")
	s, err := db.Prepare("SELECT regexp('l.s[aeiouy]', name) from (SELECT 'lisa' AS name UNION ALL SELECT 'bart' UNION ALL SELECT NULL)")
	checkNoError(t, err, "couldn't prepare statement: %s")
	defer checkFinalize(s, t)

	assert.T(t, checkStep(t, s))
	i, _, err := s.ScanInt(0)
	checkNoError(t, err, "couldn't scan result: %s")
	assert.Equal(t, 1, i)
	assert.T(t, !reused, "unexpected reused state")

	assert.T(t, checkStep(t, s))
	i, _, err = s.ScanInt(0)
	checkNoError(t, err, "couldn't scan result: %s")
	assert.Equal(t, 0, i)
	assert.T(t, reused, "unexpected reused state")

	assert.T(t, checkStep(t, s))
	i, _, err = s.ScanInt(0)
	checkNoError(t, err, "couldn't scan result: %s")
	assert.Equal(t, 0, i)
}
Esempio n. 25
0
func TestDoozerWalkWithOffsetAndLimit(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenPacket(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", "", nil, u, l, nil, 1e9, 2e9, 3e9)

	cl := dial(l.Addr().String())

	cl.Set("/test/a", store.Clobber, []byte("abc"))
	cl.Set("/test/b", store.Clobber, []byte("def"))
	cl.Set("/test/c", store.Clobber, []byte("ghi"))
	cl.Set("/test/d", store.Clobber, []byte("jkl"))

	rev, err := cl.Rev()
	if err != nil {
		panic(err)
	}

	info, err := cl.Walk("/test/**", rev, 1, 2)
	assert.Equal(t, nil, err)
	assert.Equal(t, 2, len(info))

	assert.Equal(t, "/test/b", info[0].Path)
	assert.Equal(t, "def", string(info[0].Body))
	assert.T(t, info[0].IsSet())

	assert.Equal(t, "/test/c", info[1].Path)
	assert.Equal(t, "ghi", string(info[1].Body))
	assert.T(t, info[1].IsSet())
}
Esempio n. 26
0
func TestParseGeometry(t *testing.T) {
	image := setupImage(t)
	geometry, err := image.ParseGeometry("100x100>")
	assert.T(t, err == nil)
	assert.T(t, geometry != nil)
	assert.Equal(t, 100, geometry.Width)
}
Esempio n. 27
0
func DoTestDirDescent(t *testing.T, repo fs.NodeRepo) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.F("baobab", tg.B(91, 65537)),
		tg.D("bar",
			tg.D("aleph",
				tg.F("a", tg.B(42, 65537)))),
		tg.F("bar3003", tg.B(777, 65537)))

	path := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(path)

	dir, errors := fs.IndexDir(path, repo)
	assert.Equalf(t, 0, len(errors), "%v", errors)

	for _, fpath := range []string{
		filepath.Join("foo", "baobab"),
		filepath.Join("foo", "bar", "aleph", "a"),
		filepath.Join("foo", "bar3003")} {
		node, found := fs.Lookup(dir, fpath)
		assert.Tf(t, found, "not found: %s", fpath)
		_, isFile := node.(fs.File)
		assert.T(t, isFile)
	}

	node, found := fs.Lookup(dir, filepath.Join("foo", "bar"))
	assert.T(t, found)
	_, isDir := node.(fs.Dir)
	assert.T(t, isDir)
}
Esempio n. 28
0
func Test_SpaceAddPostStepCallback(t *testing.T) {
	s := SpaceNew()
	b := BodyNew(1.0, 1.0)
	c := CircleShapeNew(b, 8.0, Vect{0.0, 0.0})

	s.AddBody(b)
	s.AddShape(c)
	result := false

	s.AddPostStepCallback(func(s2 *Space, key interface{}) {
		assert.Equal(t, b, key.(Body))
		assert.Equal(t, s, s2)
		s2.RemoveShape(c)
		s2.RemoveBody(b)
		c.Free()
		b.Free()
		result = true
	}, b)

	s.Step(0.1)
	assert.T(t, result)
	result = false
	s.Step(0.1)
	assert.T(t, !result)
	s.Step(0.1)
	assert.T(t, !result)

	s.Free()
}
Esempio n. 29
0
func TestDoozerWaitWithRev(t *testing.T) {
	l := mustListen()
	defer l.Close()
	u := mustListenUDP(l.Addr().String())
	defer u.Close()

	go Main("a", "X", "", "", "", nil, u, l, nil, 1e9, 2e9, 3e9, 101)

	cl := dial(l.Addr().String())

	// Create some history
	cl.Set("/test/foo", store.Clobber, []byte("bar"))
	cl.Set("/test/fun", store.Clobber, []byte("house"))

	ev, err := cl.Wait("/test/**", 1)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/foo", ev.Path)
	assert.Equal(t, []byte("bar"), ev.Body)
	assert.T(t, ev.IsSet())
	rev := ev.Rev + 1

	ev, err = cl.Wait("/test/**", rev)
	assert.Equal(t, nil, err)
	assert.Equal(t, "/test/fun", ev.Path)
	assert.Equal(t, []byte("house"), ev.Body)
	assert.T(t, ev.IsSet())
}
Esempio n. 30
0
func TestExecSelectWhere(t *testing.T) {
	sqlText := `
		select 
	        user_id, email, referral_count * 2, 5, yy(reg_date) > 10
	    FROM users
	    WHERE yy(reg_date) > 10 
	`
	ctx := td.TestContext(sqlText)
	job, err := exec.BuildSqlJob(ctx)
	assert.Tf(t, err == nil, "no error %v", err)

	msgs := make([]schema.Message, 0)
	resultWriter := exec.NewResultBuffer(ctx, &msgs)
	job.RootTask.Add(resultWriter)

	err = job.Setup()
	assert.T(t, err == nil)
	err = job.Run()
	time.Sleep(time.Millisecond * 10)
	assert.Tf(t, err == nil, "no error %v", err)
	assert.Tf(t, len(msgs) == 1, "should have filtered out 2 messages %v", len(msgs))
	//u.Debugf("msg: %#v", msgs[0])
	row := msgs[0].(*datasource.SqlDriverMessageMap).Values()
	//u.Debugf("row: %#v", row)
	assert.Tf(t, len(row) == 5, "expects 5 cols but got %v", len(row))
	assert.T(t, row[0] == "9Ip1aKbeZe2njCDM")
	// I really don't like this float behavior?
	assert.Tf(t, int(row[2].(float64)) == 164, "expected %v == 164  T:%T", row[2], row[2])
	assert.Tf(t, row[3] == int64(5), "wanted 5 got %v  T:%T", row[3], row[3])
	assert.T(t, row[4] == true)
}