- Inspection of goon pullrequest 69
Last active
April 19, 2018 13:20
-
-
Save hamakn/bc8f12f33e8b1252475328350a0b74d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== RUN TestPropertyLoadSaverLoadAndSave | |
== original goon == | |
&{5629499534213120 foo Zm9v} | |
&{5629499534213120 foo Zm9v} | |
&{5629499534213120 foo Zm9v} | |
&{5629499534213120 Zm9v} // => bad | |
== pullrequest 69 goon == | |
&{5066549580791808 foo Zm9v} | |
&{5066549580791808 foo Zm9v} | |
&{5066549580791808 foo Zm9v} | |
&{5066549580791808 foo Zm9v} // => Yey fixed!! | |
=== RUN TestPropertyLoadSaverLoadOnly | |
== original goon == | |
&{5629499534213120 foo} | |
&{5629499534213120 foo} // => bad | |
&{5629499534213120 foo(Load works!!) foo} | |
&{5629499534213120 foo} // => bad | |
== pullrequest 69 goon == | |
&{5066549580791808 foo} | |
&{5066549580791808 foo} // => oh... still failed | |
&{5066549580791808 foo(Load works!!) foo} | |
&{5066549580791808 foo(Load works!!) foo} // => Yey fixed!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "google.golang.org/appengine/datastore" | |
type goonInterface interface { | |
Put(src interface{}) (*datastore.Key, error) | |
Get(dst interface{}) error | |
FlushLocalCache() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/base64" | |
"fmt" | |
"testing" | |
"github.com/mjibson/goon" | |
"github.com/stretchr/testify/require" | |
goonPR69 "github.com/yuichi1004/goon" | |
"google.golang.org/appengine/aetest" | |
"google.golang.org/appengine/datastore" | |
"google.golang.org/appengine/memcache" | |
) | |
type S struct { | |
ID int64 `datastore:"-" goon:"id"` | |
Field string `datastore:"-"` | |
Base64Field string | |
} | |
func (s *S) Save() ([]datastore.Property, error) { | |
s.Base64Field = base64.StdEncoding.EncodeToString([]byte(s.Field)) | |
return datastore.SaveStruct(s) | |
} | |
func (s *S) Load(ps []datastore.Property) error { | |
err := datastore.LoadStruct(s, ps) | |
if err != nil { | |
return err | |
} | |
data, err := base64.StdEncoding.DecodeString(s.Base64Field) | |
if err != nil { | |
return err | |
} | |
s.Field = string(data) | |
return nil | |
} | |
func TestPropertyLoadSaverLoadAndSave(t *testing.T) { | |
ctx, done, err := aetest.NewContext() | |
defer done() | |
require.Nil(t, err) | |
str := "foo" | |
cases := []struct { | |
label string | |
getGoonFunc func(context.Context) goonInterface | |
}{ | |
{ | |
"original goon", | |
func(ctx context.Context) goonInterface { | |
return goon.FromContext(ctx) | |
}, | |
}, | |
{ | |
"pullrequest 69 goon", | |
func(ctx context.Context) goonInterface { | |
return goonPR69.FromContext(ctx) | |
}, | |
}, | |
} | |
for _, tc := range cases { | |
fmt.Println("== " + tc.label + " ==") | |
g := tc.getGoonFunc(ctx) | |
// setup | |
s1 := &S{Field: str} | |
_, err = g.Put(s1) | |
fmt.Println(s1) | |
// get from local cache | |
s2 := &S{ID: s1.ID} | |
g.Get(s2) | |
fmt.Println(s2) | |
// flush memcache and Goon local cache | |
memcache.Flush(ctx) | |
g.FlushLocalCache() | |
// get from datastore and write to memcached | |
s3 := &S{ID: s1.ID} | |
g.Get(s3) | |
fmt.Println(s3) | |
// get from memcached from another goon object to avoid local cache | |
gg := tc.getGoonFunc(ctx) | |
s4 := &S{ID: s1.ID} | |
gg.Get(s4) | |
fmt.Println(s4) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"testing" | |
"github.com/mjibson/goon" | |
"github.com/stretchr/testify/require" | |
goonPR69 "github.com/yuichi1004/goon" | |
"google.golang.org/appengine/aetest" | |
"google.golang.org/appengine/datastore" | |
"google.golang.org/appengine/memcache" | |
) | |
type F struct { | |
ID int64 `datastore:"-" goon:"id"` | |
InfrateField string `datastore:"-"` | |
Field string | |
} | |
func (f *F) Save() ([]datastore.Property, error) { | |
return datastore.SaveStruct(f) | |
} | |
func (f *F) Load(ps []datastore.Property) error { | |
err := datastore.LoadStruct(f, ps) | |
if err != nil { | |
return err | |
} | |
f.InfrateField = f.Field + "(Load works!!)" | |
return nil | |
} | |
func TestPropertyLoadSaverLoadOnly(t *testing.T) { | |
ctx, done, err := aetest.NewContext() | |
defer done() | |
require.Nil(t, err) | |
str := "foo" | |
cases := []struct { | |
label string | |
getGoonFunc func(context.Context) goonInterface | |
}{ | |
{ | |
"original goon", | |
func(ctx context.Context) goonInterface { | |
return goon.FromContext(ctx) | |
}, | |
}, | |
{ | |
"pullrequest 69 goon", | |
func(ctx context.Context) goonInterface { | |
return goonPR69.FromContext(ctx) | |
}, | |
}, | |
} | |
for _, tc := range cases { | |
fmt.Println("== " + tc.label + " ==") | |
g := tc.getGoonFunc(ctx) | |
// setup | |
f1 := &F{Field: str} | |
_, err = g.Put(f1) | |
fmt.Println(f1) | |
// get from local cache | |
f2 := &F{ID: f1.ID} | |
g.Get(f2) | |
fmt.Println(f2) | |
// flush memcache and Goon local cache | |
memcache.Flush(ctx) | |
g.FlushLocalCache() | |
// get from datastore and write to memcached | |
f3 := &F{ID: f1.ID} | |
g.Get(f3) | |
fmt.Println(f3) | |
// get from memcached from another goon object to avoid local cache | |
gg := tc.getGoonFunc(ctx) | |
f4 := &F{ID: f1.ID} | |
gg.Get(f4) | |
fmt.Println(f4) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. | |
[[projects]] | |
name = "github.com/davecgh/go-spew" | |
packages = ["spew"] | |
revision = "346938d642f2ec3594ed81d874461961cd0faa76" | |
version = "v1.1.0" | |
[[projects]] | |
name = "github.com/golang/protobuf" | |
packages = ["proto"] | |
revision = "925541529c1fa6821df4e44ce2723319eb2be768" | |
version = "v1.0.0" | |
[[projects]] | |
branch = "master" | |
name = "github.com/mjibson/goon" | |
packages = ["."] | |
revision = "0cd9745d6b9c43c1de754769708fb2ac349d84b2" | |
[[projects]] | |
name = "github.com/pmezard/go-difflib" | |
packages = ["difflib"] | |
revision = "792786c7400a136282c1664665ae0a8db921c6c2" | |
version = "v1.0.0" | |
[[projects]] | |
name = "github.com/stretchr/testify" | |
packages = ["assert","require"] | |
revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" | |
version = "v1.2.1" | |
[[projects]] | |
name = "github.com/yuichi1004/goon" | |
packages = ["."] | |
revision = "3d84cd76c6d15bf622305c3e8e9623603749fbb0" | |
[[projects]] | |
branch = "master" | |
name = "golang.org/x/net" | |
packages = ["context"] | |
revision = "d41e8174641f662c5a2d1c7a5f9e828788eb8706" | |
[[projects]] | |
name = "google.golang.org/appengine" | |
packages = [".","aetest","datastore","internal","internal/app_identity","internal/base","internal/datastore","internal/log","internal/memcache","internal/modules","internal/remote_api","internal/user","log","memcache","user"] | |
revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" | |
version = "v1.0.0" | |
[solve-meta] | |
analyzer-name = "dep" | |
analyzer-version = 1 | |
inputs-digest = "5dd6de695d28745ed8b58ccfae8bb3ab888bf965363268c4cd883afc415b0b48" | |
solver-name = "gps-cdcl" | |
solver-version = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment