Created
January 4, 2016 03:49
-
-
Save jshirley/713e6272f7d7c7ea997a to your computer and use it in GitHub Desktop.
This shows a failing test that I'm unable to figure out what I'm doing wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello | |
import ( | |
"appengine/aetest" | |
"appengine/datastore" | |
"reflect" | |
"testing" | |
) | |
type Foo struct { | |
Account string | |
} | |
func TestScheduleCraziness(t *testing.T) { | |
collectionName := "Foo" | |
accountName := "[email protected]" | |
ctx, err := aetest.NewContext(nil) | |
if err != nil { | |
t.Fatalf("Failed to create context: %v", err) | |
} | |
defer ctx.Close() | |
item := Foo{Account: "[email protected]"} | |
ancestorKey := datastore.NewKey(ctx, "Account", accountName, 0, nil) | |
_, err = datastore.Put(ctx, datastore.NewIncompleteKey(ctx, collectionName, ancestorKey), &item) | |
if err != nil { | |
t.Fatalf("Got an error from datastore.Put: %s\n", err) | |
return | |
} | |
var s Foo | |
query := datastore.NewQuery(collectionName).Ancestor(ancestorKey).Order("-Date").Limit(1) | |
_, err = query.Run(ctx).Next(&s) | |
if err == datastore.Done { | |
t.Errorf("No record stored. Expected %v", item) | |
return | |
} | |
if err != nil { | |
t.Errorf("Failed to fetch record: %v", err) | |
return | |
} | |
if !reflect.DeepEqual(s, item) { | |
t.Errorf("Records don't match.\nGot: %v\nWant: %v", s, item) | |
} | |
} |
As soon as I posted this gist, I realized the errors of my ways.
Date
is not indexed (in fact, I took it out to repro this case) and Order(...)
will fail on any unindexed value.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this, install the
go_appengine
package, put this in a directory in$GOPATH
and rungoapp test
, output is: