package hello import ( "appengine/aetest" "appengine/datastore" "reflect" "testing" ) type Foo struct { Account string } func TestScheduleCraziness(t *testing.T) { collectionName := "Foo" accountName := "user@example.com" ctx, err := aetest.NewContext(nil) if err != nil { t.Fatalf("Failed to create context: %v", err) } defer ctx.Close() item := Foo{Account: "admin@gmail.com"} 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) } }