Exemplo n.º 1
0
func TestPayFwd(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	pay, err := bcy.CreatePayFwd(c, PayFwd{Destination: keys1.Address})
	if err != nil {
		t.Error("CreatePayFwd error encountered: ", err)
	}
	t.Logf("%+v\n", pay)
	pay, err = bcy.GetPayFwd(c, pay.ID)
	if err != nil {
		t.Error("GetPayFwd error encountered: ", err)
	}
	t.Logf("%+v\n", pay)
	if err = bcy.DeletePayFwd(c, pay.ID); err != nil {
		t.Error("DeletePayFwd error encountered: ", err)
	}
	pays, err := bcy.ListPayFwds(c)
	if err != nil {
		t.Error("ListPayFwds error encountered: ", err)
	}
	//Should be empty
	t.Logf("%+v\n", pays)
	return
}
Exemplo n.º 2
0
func (t *testSuite) TestGame() {
	c, err := aetest.NewContext(nil)
	if c != nil {
		defer c.Close()
	}
	if err != nil {
		t.Error("Could not start aetest - %v", err)
		return
	}
	g := goon.FromContext(c)
	game := NewGame(4)
	game.Dealer = 0
	game.Players[1] = createAI()
	game.Players[1].SetHand(g, c, game, Hand{KD, QD, JD, JD, ND, TC, KC, QC, KH, NH, QS, NS}, 0, 1)
	game.Players[2] = createAI()
	game.Players[2].SetHand(g, c, game, Hand{AD, AD, KD, ND, NC, NC, TH, JH, AS, JS, JS, NS}, 0, 2)
	game.Players[3] = createAI()
	game.Players[3].SetHand(g, c, game, Hand{AC, AC, KC, JC, JC, TH, QH, QH, JH, AS, TS, KS}, 0, 3)
	game.Players[0] = createAI()
	game.Players[0].SetHand(g, c, game, Hand{TD, TD, QD, TC, QC, AH, AH, KH, NH, TS, KS, QS}, 0, 0)
	game.Meld = make([]uint8, len(game.Players)/2)
	game.CountMeld = make([]bool, len(game.Players)/2)
	game.Counters = make([]uint8, len(game.Players)/2)
	game.HighBid = 20
	game.HighPlayer = game.Dealer
	game.State = StateBid
	game.Next = game.Dealer
	//oright = game.Players[0].(*AI).HT
	//Log(oright.Owner, "Start of game hands")
	//oright.Debug()
	game.inc() // so dealer's not the first to bid

	game.processAction(g, c, nil, game.Players[game.Next].Tell(nil, nil, game, CreateBid(0, game.Next)))
	t.True(true) // just getting to the end successfully counts!
}
Exemplo n.º 3
0
func TestLoadStoreTokens(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatalf("Couldn't start local datastore: %s", err)
	}
	defer c.Close()

	tok, err := NewToken(userID, path, now)
	if err != nil {
		t.Fatalf("Error creating token: %s", err)
	}
	if err := tok.Store(c); err != nil {
		t.Fatalf("Error storing token: %s", err)
	}
	tok1, err := TokenForRequest(c, userID, path)
	if err != nil {
		t.Fatalf("Error looking up token: %s", err)
	}
	if !reflect.DeepEqual(tok, tok1) {
		t.Errorf("Tokens don't match; %v instead of %v", tok1, tok)
	}
	tok.Delete(c)
	_, err = TokenForRequest(c, userID, path)
	if err != ErrTokenNotFound {
		t.Errorf("Should not have found token on second lookup")
	}
}
Exemplo n.º 4
0
func TestPlayerSaveNoSeason(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	name := "Player Name"
	email := "*****@*****.**"
	faction := "Skorne"
	err = SavePlayer(c, nil, name, email, faction)
	if err != nil {
		t.Fatalf("Error saving player: %v", err)
	}
	p := LoadPlayer(c, nil, email)
	if p == nil {
		t.Fatal("Loading player gave us a nil player")
	}
	if p.Name != name {
		t.Errorf("Expected player name to be '%s' not '%s'", name, p.Name)
	}
	if p.Email != email {
		t.Errorf("Expected player email to be '%s' instead it was '%s'", email, p.Email)
	}
	if p.Faction != faction {
		t.Errorf("Expected player faction to be '%s' instead it was '%s'", faction, p.Faction)
	}
}
Exemplo n.º 5
0
func TestAppEngine(t *testing.T) {
	ctx, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer ctx.Close()

	cache := New(ctx)

	key := "testKey"
	_, ok := cache.Get(key)
	if ok {
		t.Fatal("retrieved key before adding it")
	}

	val := []byte("some bytes")
	cache.Set(key, val)

	retVal, ok := cache.Get(key)
	if !ok {
		t.Fatal("could not retrieve an element we just added")
	}
	if !bytes.Equal(retVal, val) {
		t.Fatal("retrieved a different value than what we put in")
	}

	cache.Delete(key)

	_, ok = cache.Get(key)
	if ok {
		t.Fatal("deleted key still present")
	}
}
Exemplo n.º 6
0
func TestHandlers(t *testing.T) {
	_, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	resp := httptest.NewRecorder()
	uri := "/api/tasks/"
	var testjson1 = `{"summary" : "task1",
                "content" : ["taskcontent1"],
    "done": false}`
	instance, err := aetest.NewInstance(nil)
	if err != nil {
		t.Fatal(err)
	}
	req, err := instance.NewRequest("POST", uri, ioutil.NopCloser(strings.NewReader(testjson1)))
	http.DefaultServeMux.ServeHTTP(resp, req)
	if p, err := ioutil.ReadAll(resp.Body); err != nil {
		t.Fail()

	} else {
		if strings.Contains(string(p), "Error") {
			t.Errorf("header response shouldn't return error: %s: ", p)
		}
		if !strings.Contains(string(p), "task1") {
			t.Errorf("header response doesn't match: \n%s", p)
		}
	}

	getreq, err := instance.NewRequest("GET", uri, nil)
	if err != nil {
		t.Fatal(err)
	}
	http.DefaultServeMux.ServeHTTP(resp, getreq)
	if p, err := ioutil.ReadAll(resp.Body); err != nil {
		t.Fail()
	} else {
		if strings.Contains(string(p), "Error") {
			t.Errorf("header response shouldn't return erros: %s: ", p)
		}
		if !strings.Contains(string(p), "task1") {
			t.Errorf("header response doesn't match: \n%s", p)
		}
		if !strings.Contains(string(p), "taskcontent1") {
			t.Errorf("header reponse doesn't match: \n%s", p)
		}
	}
	uri = "/api/task/5629499534213120"
	delreq, err := instance.NewRequest("DELETE", uri, nil)
	if err != nil {
		t.Fatal(err)
	}
	http.DefaultServeMux.ServeHTTP(resp, delreq)
	if p, err := ioutil.ReadAll(resp.Body); err != nil {
		t.Fail()
	} else {
		if strings.Contains(string(p), "Error") {
			t.Errorf("header response shouldn't return error: %s: ", p)
		}
	}
}
Exemplo n.º 7
0
func TestMicro(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	result, err := bcy.SendMicro(c, MicroTX{Priv: keys2.Private, ToAddr: keys1.Address, Value: 25000})
	if err != nil {
		t.Error("Error encountered: ", err)
	}
	t.Logf("%+v\n", result)
	//Test public key signing method
	micpub, err := bcy.SendMicro(c, MicroTX{Pubkey: keys2.Public, ToAddr: keys1.Address, Value: 15000})
	if err != nil {
		t.Error("Error encountered: ", err)
	}
	t.Logf("First MicroTX Pubkey call: %+v\n", micpub)
	//Sign resultpub
	err = micpub.Sign(keys2.Private)
	if err != nil {
		t.Error("Error encountered: ", err)
	}
	t.Logf("Signed MicroTX: %+v\n", micpub)
	//Send signed resultpub
	resultpub, err := bcy.SendMicro(c, micpub)
	if err != nil {
		t.Error("Error encountered: ", err)
	}
	t.Logf("Final MicroTX Pubkey call: %+v\n", resultpub)
	return
}
Exemplo n.º 8
0
func TestKeyAndSaveAndList(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	t1 := Task{Summary: "some summary", Id: 123}
	t2 := Task{Summary: "second summary", Id: 222}
	if _, err := t1.save(c); err != nil {
		t.Fatal(err)
	}
	if _, err := t2.save(c); err != nil {
		t.Fatal(err)
	}
	k1 := t1.key(c)
	k1id := k1.IntID()
	if k1id != 123 {
		t.Error("Expected 123, got: ", k1id)
	}
	k2 := t2.key(c)
	k2id := k2.IntID()
	if k2id != 222 {
		t.Error("Expected 222, got: ", k2id)
	}
	tasks, err := listTasks(c)
	if err != nil {
		t.Fatal(err)
	}
	if tasks[0].Id != 123 {
		t.Error("Expected 123, got: ", tasks[0].Id)
	}
	if tasks[1].Id != 222 {
		t.Error("Expected 222, got: ", tasks[1].Id)
	}
}
Exemplo n.º 9
0
func TestOpHandler_AddSucess(t *testing.T) {
	c, err := aetest.NewContext(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	// The test has two operations. One is added at investment creation and the other is added via handler.
	firstOp, _ := NewOperationFromString(typeStr, valueStr, firstOpDateStr)
	secondOp, _ := NewOperationFromString(typeStr, valueStr, dateStr)
	// Adding investment along with first operation.
	inv := &Investment{Name: "testInv", Ops: Operations{firstOp}}
	if err := PutInvestment(c, inv); err != nil {
		t.Fatal(err)
	}
	// This should add an operation that is exactly like second operation.
	form := url.Values{OpsParamInv: {inv.Key}, OpsParamType: {typeStr}, OpsParamValue: {valueStr}, OpsParamDate: {dateStr}}
	if err := handleOp(c, &http.Request{Form: form}); err != nil {
		t.Fatalf("handleOp want nil got:%q", err)
	}
	gotInv, err := GetInvestment(c, inv.Key)
	if err != nil {
		t.Errorf("getInvestment returned an error: %q", err)
	}
	// Even though firstOp happened latter, operations must be chronologically sorted.
	if !reflect.DeepEqual(firstOp, gotInv.Ops[0]) { // There is already one operation inserted.
		t.Errorf("want:%v got:%v", firstOp, gotInv.Ops[0])
	}
	if !reflect.DeepEqual(secondOp, gotInv.Ops[1]) { // There is already one operation inserted.
		t.Errorf("want:%v got:%v", secondOp, gotInv.Ops[1])
	}
}
Exemplo n.º 10
0
func initFileSystems() (fss []fsi.FileSystem, c aetest.Context) {

	var err error
	c, err = aetest.NewContext(nil)
	if err != nil {
		log.Fatal(err)
	}

	// defer c.Close()
	// Not here, but instead at the start of the test-funcs

	// We cant make variadic options generic,
	// since they need the concrete filesystem type.
	fs1 := dsfs.New(
		dsfs.MountName(dsfs.MountPointLast()),
		dsfs.AeContext(c),
	)

	fs3 := osfs.New()

	fs4 := memfs.New(
		memfs.Ident("m"),
	)

	fss = []fsi.FileSystem{fs1, fs3, fs4}

	return fss, c
}
Exemplo n.º 11
0
func (s *S) Test(c *C) {
	ctx, err := aetest.NewContext(nil)
	if err != nil {
		c.Fatal(err)
	}
	defer ctx.Close()

	cache := New(ctx)

	key := "testKey"
	_, ok := cache.Get(key)

	c.Assert(ok, Equals, false)

	val := []byte("some bytes")
	cache.Set(key, val)

	retVal, ok := cache.Get(key)
	c.Assert(ok, Equals, true)
	c.Assert(bytes.Equal(retVal, val), Equals, true)

	cache.Delete(key)

	_, ok = cache.Get(key)
	c.Assert(ok, Equals, false)
}
Exemplo n.º 12
0
func TestPlayerSaveNoSeason(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	name := "Player Name"
	faction := "Skorne"
	player := Player{
		Name:    name,
		Faction: faction,
	}
	players := make([]Player, 1)
	players[0] = player
	SavePlayers(c, nil, players)
	p := LoadPlayer(c, nil, name)
	if p == nil {
		t.Fatal("Loading player gave us a nil player")
	}
	if p.Name != name {
		t.Errorf("Expected player name to be '%s' not '%s'", name, p.Name)
	}
	if p.Faction != faction {
		t.Errorf("Expected player faction to be '%s' instead it was '%s'", faction, p.Faction)
	}
}
Exemplo n.º 13
0
func TestEditTask(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	key := datastore.NewKey(c, "Task", "", 123456789, defaultTaskList(c))
	id, _ := strconv.ParseInt("123456789", 10, 64)
	if id != 123456789 {
		t.Fatal(err)
	}
	if _, err := datastore.Put(c, key, &Task{Summary: "some summary"}); err != nil {
		t.Fatal(err)
	}
	task1ret := Task{}
	newkey := keyForID(c, id)
	if err := datastore.Get(c, newkey, &task1ret); err != nil {
		t.Fatal(err)
	}
	tid := newkey.IntID()
	if task1ret.Summary != "some summary" {
		t.Error("Expected <some summary>, got: ", task1ret.Summary)
	}
	if tid != 123456789 {
		t.Error("Expected id 123456789, got: ", tid)
	}

}
Exemplo n.º 14
0
// TestSuccessCodeAndInfoForComplexMessage sends out a complex message to the pubnub channel
// The response is parsed and should match the 'sent' status.
// _publishSuccessMessage and customstruct is defined in the common.go file
func TestSuccessCodeAndInfoForComplexMessage(t *testing.T) {
	context, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer context.Close()
	uuid := ""
	w, req := InitAppEngineContext(t)

	pubnubInstance := messaging.New(context, uuid, w, req, PubKey, SubKey, "", "", false)

	//pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "", "", false)
	channel := "testChannel"

	customStruct := CustomStruct{
		Foo: "hi!",
		Bar: []int{1, 2, 3, 4, 5},
	}

	returnChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	responseChannel := make(chan string)
	waitChannel := make(chan string)

	//go pubnubInstance.Publish(channel, customStruct, returnChannel, errorChannel)
	go pubnubInstance.Publish(context, w, req, channel, customStruct, returnChannel, errorChannel)
	go ParsePublishResponse(returnChannel, channel, publishSuccessMessage, "SuccessCodeAndInfoForComplexMessage", responseChannel)

	go ParseErrorResponse(errorChannel, responseChannel)
	go WaitForCompletion(responseChannel, waitChannel)
	ParseWaitResponse(waitChannel, t, "SuccessCodeAndInfoForComplexMessage")
	time.Sleep(2 * time.Second)
}
Exemplo n.º 15
0
func TestListTasks(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	assert := assert.New(t)
	t1 := Task{Summary: "task1", Done: true}
	t2 := Task{Summary: "task2", Done: false}
	t1n, err := t1.save(c)
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t1n.Done, true)
	t2n, err := t2.save(c)
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t2n.Done, false)
	tasklist, err := listTasks(c)
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(tasklist[0].Summary, "task2")
	assert.Equal(tasklist[1].Done, true)
}
Exemplo n.º 16
0
// TestNullMessage sends out a null message to a pubnub channel. The response should
// be an "Invalid Message".
func TestNullMessage(t *testing.T) {
	context, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer context.Close()
	uuid := ""
	w, req := InitAppEngineContext(t)

	pubnubInstance := messaging.New(context, uuid, w, req, PubKey, SubKey, "", "", false)

	//pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "")
	channel := "testChannel"
	var message interface{}
	message = nil
	returnChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	responseChannel := make(chan string)
	waitChannel := make(chan string)

	//go pubnubInstance.Publish(channel, message, returnChannel, errorChannel)
	go pubnubInstance.Publish(context, w, req, channel, message, returnChannel, errorChannel)
	//go ParsePublishResponse(returnChannel, channel, "Invalid Message", "NullMessage", responseChannel)
	go ParseResponseDummy(returnChannel)
	go ParseErrorResponseForTestSuccess("Invalid Message", errorChannel, responseChannel)
	//go ParseErrorResponse(errorChannel, responseChannel)
	go WaitForCompletion(responseChannel, waitChannel)
	ParseWaitResponse(waitChannel, t, "NullMessage")
}
Exemplo n.º 17
0
// TestSuccessCodeAndInfo sends out a message to the pubnub channel
// The response is parsed and should match the 'sent' status.
// _publishSuccessMessage is defined in the common.go file
func TestSuccessCodeAndInfo(t *testing.T) {
	context, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer context.Close()
	uuid := ""
	w, req := InitAppEngineContext(t)

	pubnubInstance := messaging.New(context, uuid, w, req, PubKey, SubKey, "", "", false)
	//pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "")
	channel := "testChannel"
	message := "Pubnub API Usage Example"
	returnChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	responseChannel := make(chan string)
	waitChannel := make(chan string)

	//go pubnubInstance.Publish(channel, message, returnChannel, errorChannel)
	go pubnubInstance.Publish(context, w, req, channel, message, returnChannel, errorChannel)
	go ParsePublishResponse(returnChannel, channel, publishSuccessMessage, "SuccessCodeAndInfo", responseChannel)

	go ParseErrorResponse(errorChannel, responseChannel)
	go WaitForCompletion(responseChannel, waitChannel)
	ParseWaitResponse(waitChannel, t, "SuccessCodeAndInfo")
	time.Sleep(2 * time.Second)
}
Exemplo n.º 18
0
func TestCacheNil(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}

	h := holder{key: datastore.NewKey(c, "Holder", "testKey_testCacheNil", 0, nil)}
	err = Load(c, &h)
	if expected := datastore.ErrNoSuchEntity; err != expected {
		t.Errorf("expected error %v, was %v", expected, err)
	}

	value := &codecValue{}
	_, err = nullCodec.Get(c, cacheKey(h.key), value)
	if err != nil {
		t.Errorf("expected nil error for memcache get, was %v", err)
	}
	if value.X != nil {
		t.Errorf("expected nil storable, was %v", value.X)
	}

	err = Load(c, &h)
	if expected := datastore.ErrNoSuchEntity; err != expected {
		t.Errorf("expected error %v, was %v", expected, err)
	}
}
Exemplo n.º 19
0
func TestWithdrawOkay(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	sc := make(chan string)
	key := datastore.NewKey(c, "BankAccount", "", 1, nil)
	if _, err := datastore.Put(c, key, &BankAccount{100}); err != nil {
		t.Fatal(err)
	}

	donec := make(chan bool)
	go func() {
		if msg, want := <-sc, "myid: balance is $0000100  (attempt number 0)\n"; msg != want {
			t.Errorf("Message %q, want %q", msg, want)
		}
		donec <- true
	}()

	err = withdraw(c, sc, "myid", 42, 0)
	if err != nil {
		t.Fatalf("Error: %v; want no error", err)
	}

	if bal, want := balance(c, t), 58; bal != want {
		t.Errorf("Balance %d, want %d", bal, want)
	}

	<-donec
}
Exemplo n.º 20
0
func prepare(t *testing.T) aetest.Context {

	lg, lge := loghttp.Logger(nil, nil)
	_ = lg

	c, err := aetest.NewContext(nil)
	if err != nil {
		lge(err)
		t.Fatal(err)
	}

	serveFile := func(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
		fs1 := repo.GetFS(c)
		fileserver.FsiFileServer(w, r, fileserver.Options{FS: fs1, Prefix: repo.UriMountNameY})
	}
	http.HandleFunc(repo.UriMountNameY, loghttp.Adapter(serveFile))

	go func() {
		log.Fatal(
			http.ListenAndServe(cTestHostOwn, nil),
		)
	}()

	return c

}
Exemplo n.º 21
0
func TestStaff(t *testing.T) {
	users := []*account.Account{{
		ID: "0x1",
		Info: account.Info{
			FirstName: "a",
			LastName:  "b",
			Email:     "*****@*****.**",
		}}, {
		ID: "0x2",
		Info: account.Info{
			FirstName: "aa",
			LastName:  "bb",
			Email:     "*****@*****.**",
		}}, {
		ID: "0x3",
		Info: account.Info{
			FirstName: "aaa",
			LastName:  "bbb",
			Email:     "*****@*****.**",
		}}}
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	for i, user := range users {
		if _, err := ForUserAccount(c, user); err == nil {
			t.Errorf("Shouldn't have found staff for user %d", i)
		}
		staff := New(user)
		if err := staff.Store(c); err != nil {
			t.Fatalf("Failed to store staff %d: %s", i, err)
		}
		if found, err := ForUserAccount(c, user); err != nil {
			t.Errorf("Didn't find staff %d: %s", i, err)
		} else if !reflect.DeepEqual(staff, found) {
			t.Errorf("Found wrong staff; %v vs %v", found, staff)
		}
		if found, err := WithID(c, user.ID); err != nil {
			t.Errorf("Didn't find staff %d by ID: %s", i, err)
		} else if !reflect.DeepEqual(staff, found) {
			t.Errorf("Found wrong staff %d by ID: %v vs %v", found, staff)
		}
	}
	expected := usersToStaff(users)
	allStaff, err := All(c)
	if err != nil {
		t.Fatalf("Error reading all staff: %s", err)
	}
	if got, want := len(allStaff), len(expected); got != want {
		t.Fatalf("Wrong number of staff; %d vs %d", got, want)
	}
	sort.Sort(ByName(expected))
	sort.Sort(ByName(allStaff))
	for i, want := range expected {
		if got := allStaff[i]; !reflect.DeepEqual(got, want) {
			t.Errorf("Wrong staff at %d; %v vs %v", i, got, want)
		}
	}
}
func TestLoadBatchFromDatastore(t *testing.T) {
	gaeCtx, _ := aetest.NewContext(nil)
	defer gaeCtx.Close()

	Convey("Given I have a load batch from datastore transformer", t, func() {
		riversCtx := rivers.NewContext()
		loadBatchProcessor := appx.NewStep(riversCtx).LoadBatchFromDatastore(gaeCtx)

		Convey("And I have a few entities in datastore", func() {
			user1 := NewUser(User{
				Name:  "Borges",
				Email: "*****@*****.**",
				SSN:   "123123123",
			})

			user2 := NewUser(User{
				Name:  "Borges",
				Email: "*****@*****.**",
				SSN:   "123123123",
			})

			err := appx.NewKeyResolver(gaeCtx).Resolve(user1)
			So(err, ShouldBeNil)
			err = appx.NewKeyResolver(gaeCtx).Resolve(user2)
			So(err, ShouldBeNil)

			_, err = datastore.Put(gaeCtx, user1.Key(), user1)
			So(err, ShouldBeNil)
			_, err = datastore.Put(gaeCtx, user2.Key(), user2)
			So(err, ShouldBeNil)

			Convey("When I transform the incoming batch", func() {
				userFromDatastore1 := NewUser(User{Name: user1.Name})
				userFromDatastore2 := NewUser(User{Name: user2.Name})
				appx.NewKeyResolver(gaeCtx).Resolve(userFromDatastore1)
				appx.NewKeyResolver(gaeCtx).Resolve(userFromDatastore2)

				batch := &appx.DatastoreBatch{
					Size: 2,
					Keys: []*datastore.Key{
						userFromDatastore1.Key(),
						userFromDatastore2.Key(),
					},
					Items: []appx.Entity{
						userFromDatastore1,
						userFromDatastore2,
					},
				}

				loadBatchProcessor(batch)

				Convey("And entities are loaded from datastore", func() {
					So(userFromDatastore1, ShouldResemble, user1)
					So(userFromDatastore2, ShouldResemble, user2)
				})
			})
		})
	})
}
Exemplo n.º 23
0
func dbConnect(url string) (*Database, error) {
	gaeContext, err := aetest.NewContext(nil)
	if err != nil {
		return nil, err
	}

	return Connect(url, gaeContext)
}
Exemplo n.º 24
0
func TestDispatchCommand(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

}
Exemplo n.º 25
0
func TestAsset(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	oap1, err := bcy.GenAssetKeychain(c)
	oap2, err := bcy.GenAssetKeychain(c)
	funder, err := bcy.GenAddrKeychain(c)
	_, err = bcy.Faucet(c, funder, 1e6)
	_, err = bcy.Faucet(c, oap1, 1e6)
	if err != nil {
		t.Error("GenAsset/AddrKeychain or Faucet error encountered: ", err)
	}
	tx1, err := bcy.IssueAsset(c, OAPIssue{funder.Private, oap1.OAPAddress, 9000, ""})
	if err != nil {
		t.Error("IssueAsset error encountered: ", err)
	}
	//wait until tx1 is confirmed
	fmt.Printf("Waiting for asset issuance to confirm.")
	for {
		conf, err := bcy.GetTXConf(c, tx1.Hash)
		if err != nil {
			t.Logf("Error polling for Issue Asset tx confirmation: ", err)
			break
		}
		if conf.Confidence == 1 {
			fmt.Printf("\n")
			break
		}
		fmt.Printf(".")
		time.Sleep(2 * time.Second)
	}
	tx2, err := bcy.TransferAsset(c, OAPIssue{oap1.Private, oap2.OAPAddress, 8999, ""}, tx1.AssetID)
	if err != nil {
		t.Error("TransferAsset error encountered: ", err)
		t.Errorf("Returned OAPTX1:%+v\n", tx1)
		t.Errorf("Returned OAPTX2:%+v\n", tx2)
	}
	txs, err := bcy.ListAssetTXs(c, tx1.AssetID)
	if err != nil {
		t.Error("ListAssetTXs error encountered: ", err)
		t.Errorf("Returned TXs:%v\n", txs)
	}
	checktx, err := bcy.GetAssetTX(c, tx1.AssetID, tx1.Hash)
	if err != nil {
		t.Error("GetAssetTX error encountered: ", err)
		t.Errorf("Original OAPTX from first issue: %+v\n", tx1)
		t.Errorf("Returned OAPTX from GetAssetTX endpoint: %+v\n", checktx)
	}
	oapaddr, err := bcy.GetAssetAddr(c, tx1.AssetID, oap1.OAPAddress)
	if err != nil {
		t.Error("GetAssetAddr error encountered: ", err)
		t.Errorf("Original OAPTX from first issue: %+v\n", tx1)
		t.Errorf("Returned Addr from GetAssetAddr endpoint: %+v\n", oapaddr)
	}
	t.Logf("Returned Addr from GetAssetAddr endpoint: %+v\n", oapaddr)
}
Exemplo n.º 26
0
func TestGetAwsConfig(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()

	GetAwsConfig(c)
}
Exemplo n.º 27
0
func (o *datastoreOpener) Open(t T) (*Orm, interface{}) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	orm := newOrm(t, "datastore://", true)
	orm.Driver().(*datastore.Driver).SetContext(c)
	return orm, c
}
Exemplo n.º 28
0
func TestGoodRegistration(t *testing.T) {
	ctx, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer ctx.Close()

	var testID = "test-id-🔒"

	// Mimic NewChallenge
	ckey := makeKey(ctx, testID, "Challenge")
	_, err = datastore.Put(ctx, ckey, &fakeRegistrationChallenge)
	if err != nil {
		t.Fatalf("datastore.Put error: %v", err)
	}
	// log.Printf("Challenge: %+v", fakeRegistrationChallenge)

	if err := StoreResponse(ctx, testID, fakeRegistrationResponse); err != nil {
		t.Fatalf("StoreRegistration: %v", err)
	}

	// Load what was just saved and verify it.
	pkey := MakeParentKey(ctx)
	q := datastore.NewQuery("Registration").
		Ancestor(pkey).
		Filter("UserIdentity =", testID)
	qt := q.Run(ctx)

	if count, err := q.Count(ctx); err != nil {
		t.Fatalf("Count error: %v", err)
	} else if count != 1 {
		t.Fatalf("Expected only 1 item to be found.")
	}

	var regi Registration
	if _, err = qt.Next(&regi); err != nil {
		t.Fatalf("datastore.Get (%+v): %+v", qt, regi)
	}

	// Verify the stored info.
	if regi.Counter != 0 {
		t.Error("Expected Counter to be 0")
	}

	if regi.UserIdentity != testID {
		t.Error("Expected user identity %v to be %v", regi.UserIdentity,
			testID)
	}

	// TODO: Ensure we delete the challenge.

	u2fReg := new(u2f.Registration)
	if err := u2fReg.UnmarshalBinary(regi.U2FRegistrationBytes); err != nil {
		t.Fatalf("Unable to convert registration to struct: %+v", err)
	}
}
Exemplo n.º 29
0
func getContext(t *testing.T) appengine.Context {
	c, err := aetest.NewContext(nil)
	if err != nil {
		if t != nil {
			t.Fatal(err)
		}
	}

	return c
}
Exemplo n.º 30
0
func TestComposeNewsletter(t *testing.T) {
	c, err := aetest.NewContext(nil)
	if err != nil {
		t.Fatal(err)
	}
	defer c.Close()
	label, err := SaveLabel("casa", c)
	labels, err := GetPortals(c, "")
	t.Errorf("composeMessage(), %s, %s. %s", label, labels, err)
}