astaxie / beegae

beego for GAE
Other
38 stars 11 forks source link

Appengine Context in tests (appengine/aetest) #10

Open kalbasit opened 10 years ago

kalbasit commented 10 years ago

Google groups discussion Example application

Appengine ship with aetest package that allows you run the tests against an appengine instance.

We need to figure out how to pass the Appengine context from the tests all the way to the controller interface like the example in the aetest package:

package foo_test

import (
"testing"

"appengine/memcache"
"appengine/aetest"
)

func TestFoo(t *testing.T) {
        c, err := aetest.NewContext(nil)
        if err != nil {
                t.Fatal(err)
        }
        defer c.Close()

        it := &memcache.Item{
                Key:   "some-key",
                Value: []byte("some-value"),
        }
        err = memcache.Set(c, it)
        if err != nil {
                t.Fatalf("Set err: %v", err)
        }
        it, err = memcache.Get(c, "some-key")
        if err != nil {
                t.Fatalf("Get err: %v; want no error", err)
        }
        if g, w := string(it.Value), "some-value" ; g != w {
                t.Errorf("retrieved Item.Value = %q, want %q", g, w)
        }
}
someone1 commented 10 years ago

What do you think of the approach in PR#12? This does not propagate the test context to the actual session driver though. This would require much more thought and a possible re-write of the driver.