go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/docs/present/lightning/gae_test.go (about) 1 // Copyright 2016 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build !native_appengine 16 // +build !native_appengine 17 18 package demo 19 20 import ( 21 "context" 22 "testing" 23 24 "go.chromium.org/luci/gae/impl/memory" 25 "go.chromium.org/luci/gae/service/datastore" 26 27 . "github.com/smartystreets/goconvey/convey" 28 ) 29 30 // START OMIT 31 32 // HL 33 34 func TestGAE(t *testing.T) { 35 type Model struct { // HL 36 ID string `gae:"$id"` // HL 37 A, B int // HL 38 } // HL 39 Convey("Put/Get w/ gae", t, func() { 40 ctx := memory.Use(context.Background()) 41 So(datastore.Put(ctx, // HL 42 &Model{"one thing", 10, 20}, // HL 43 &Model{"or another", 20, 30}), ShouldBeNil) // HL 44 ms := []*Model{{ID: "one thing"}, {ID: "or another"}} 45 So(datastore.Get(ctx, ms), ShouldBeNil) // HL 46 So(ms, ShouldResemble, []*Model{{"one thing", 10, 20}, {"or another", 20, 30}}) 47 }) 48 } 49 50 // END OMIT