| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 1 // +build !native_appengine | 5 // +build !native_appengine |
| 2 | 6 |
| 3 package demo | 7 package demo |
| 4 | 8 |
| 5 import "testing" | 9 import "testing" |
| 6 import "golang.org/x/net/context" | 10 import "golang.org/x/net/context" |
| 7 import "github.com/luci/gae/impl/memory" | 11 import "github.com/luci/gae/impl/memory" |
| 8 import . "github.com/smartystreets/goconvey/convey" | 12 import . "github.com/smartystreets/goconvey/convey" |
| 9 | 13 |
| 10 // START OMIT | 14 // START OMIT |
| 11 | 15 |
| 12 import "github.com/luci/gae/service/datastore" // HL | 16 import "github.com/luci/gae/service/datastore" // HL |
| 13 | 17 |
| 14 func TestGAE(t *testing.T) { | 18 func TestGAE(t *testing.T) { |
| 15 type Model struct { // HL | 19 type Model struct { // HL |
| 16 ID string `gae:"$id"` // HL | 20 ID string `gae:"$id"` // HL |
| 17 A, B int // HL | 21 A, B int // HL |
| 18 } // HL | 22 } // HL |
| 19 Convey("Put/Get w/ gae", t, func() { | 23 Convey("Put/Get w/ gae", t, func() { |
| 20 ctx := memory.Use(context.Background()) | 24 ctx := memory.Use(context.Background()) |
| 21 » » ds := datastore.Get(ctx) // get datastore client | 25 » » So(datastore.Put(ctx, // HL |
| 22 » » So(ds.Put( // HL | |
| 23 &Model{"one thing", 10, 20}, // HL | 26 &Model{"one thing", 10, 20}, // HL |
| 24 &Model{"or another", 20, 30}), ShouldBeNil) // HL | 27 &Model{"or another", 20, 30}), ShouldBeNil) // HL |
| 25 ms := []*Model{{ID: "one thing"}, {ID: "or another"}} | 28 ms := []*Model{{ID: "one thing"}, {ID: "or another"}} |
| 26 » » So(ds.Get(ms), ShouldBeNil) // HL | 29 » » So(datastore.Get(ctx, ms), ShouldBeNil) // HL |
| 27 So(ms, ShouldResemble, []*Model{{"one thing", 10, 20}, {"or anot
her", 20, 30}}) | 30 So(ms, ShouldResemble, []*Model{{"one thing", 10, 20}, {"or anot
her", 20, 30}}) |
| 28 }) | 31 }) |
| 29 } | 32 } |
| 30 | 33 |
| 31 // END OMIT | 34 // END OMIT |
| OLD | NEW |