Google App Engine Datastore - Testing Queries fails

后端 未结 3 1140
终归单人心
终归单人心 2020-12-11 07:42

I am currently trying to test a piece of my code that runs a query on the datastore before putting in a new entity to ensure that duplicates are not created. The code I wrot

3条回答
  •  一个人的身影
    2020-12-11 08:43

    To compliment @JohnGB's answer in the latest version of aetest, there are more steps to get a context with strong consistency. First create an instance, then create a request from that instance, which you can use to produce a context.

    inst, err := aetest.NewInstance(
    &aetest.Options{StronglyConsistentDatastore: true})
    
    if err != nil {
        t.Fatal(err)
    }
    defer inst.Close()
    
    req, err := inst.NewRequest("GET", "/", nil)
    if err != nil {
        t.Fatal(err)
    }
    
    ctx := appengine.NewContext(req)
    

提交回复
热议问题