Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: go/src/infra/appengine/test-results/model/test_file_test.go

Issue 2250023002: test-results: bug fixes and tests for TestFile Put, PutData (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@cl-ing_upload
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/appengine/test-results/model/test_file.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package model 1 package model
2 2
3 import ( 3 import (
4 "bytes"
4 "io/ioutil" 5 "io/ioutil"
6 "path/filepath"
5 "testing" 7 "testing"
6 8
7 "github.com/luci/gae/impl/memory" 9 "github.com/luci/gae/impl/memory"
8 "github.com/luci/gae/service/datastore" 10 "github.com/luci/gae/service/datastore"
9 "golang.org/x/net/context" 11 "golang.org/x/net/context"
10 12
11 . "github.com/smartystreets/goconvey/convey" 13 . "github.com/smartystreets/goconvey/convey"
12 ) 14 )
13 15
14 func TestTestFile(t *testing.T) { 16 func TestTestFile(t *testing.T) {
15 t.Parallel() 17 t.Parallel()
16 18
17 Convey("TestFile", t, func() { 19 Convey("TestFile", t, func() {
18 c := memory.Use(context.Background()) 20 c := memory.Use(context.Background())
19 ds := datastore.Get(c) 21 ds := datastore.Get(c)
20 testFileIdx, err := datastore.FindAndParseIndexYAML("testdata") 22 testFileIdx, err := datastore.FindAndParseIndexYAML("testdata")
21 So(err, ShouldBeNil) 23 So(err, ShouldBeNil)
22 ds.Testable().AddIndexes(testFileIdx...) 24 ds.Testable().AddIndexes(testFileIdx...)
23 25
24 » » dataEntries := []DataEntry{ 26 » » Convey("Get", func() {
25 » » » {Data: []byte("hello, "), ID: 142}, 27 » » » dataEntries := []DataEntry{
26 » » » {Data: []byte("world"), ID: 199}, 28 » » » » {Data: []byte("hello, "), ID: 142},
27 » » } 29 » » » » {Data: []byte("world"), ID: 199},
30 » » » }
28 31
29 » » for _, de := range dataEntries { 32 » » » for _, de := range dataEntries {
30 » » » So(ds.Put(&de), ShouldBeNil) 33 » » » » So(ds.Put(&de), ShouldBeNil)
31 » » } 34 » » » }
32 35
33 » » dataKeys := make([]*datastore.Key, len(dataEntries)) 36 » » » dataKeys := make([]*datastore.Key, len(dataEntries))
34 » » for i, de := range dataEntries { 37 » » » for i, de := range dataEntries {
35 » » » dataKeys[i] = ds.KeyForObj(&de) 38 » » » » dataKeys[i] = ds.KeyForObj(&de)
36 » » } 39 » » » }
37 40
38 » » tf1 := TestFile{ 41 » » » tf1 := TestFile{
39 » » » ID: 1, 42 » » » » ID: 1,
40 » » » Name: "full_results.json", 43 » » » » Name: "full_results.json",
41 » » » Master: "Chromium", 44 » » » » Master: "Chromium",
42 » » » DataKeys: dataKeys, 45 » » » » DataKeys: dataKeys,
43 » » } 46 » » » }
44 47
45 » » So(ds.Put(&tf1), ShouldBeNil) 48 » » » So(ds.Put(&tf1), ShouldBeNil)
46 » » ds.Testable().CatchupIndexes() 49 » » » ds.Testable().CatchupIndexes()
47 50
48 » » Convey("Should get an existing TestFile by ID", func() { 51 » » » Convey("get an existing TestFile by ID", func() {
49 » » » tf := TestFile{ID: 1} 52 » » » » tf := TestFile{ID: 1}
50 » » » So(ds.Get(&tf), ShouldBeNil) 53 » » » » So(ds.Get(&tf), ShouldBeNil)
51 » » » So(tf.ID, ShouldEqual, 1) 54 » » » » So(tf.ID, ShouldEqual, 1)
52 » » » So(tf.Name, ShouldEqual, "full_results.json") 55 » » » » So(tf.Name, ShouldEqual, "full_results.json")
53 » » » So(tf.Master, ShouldEqual, "Chromium") 56 » » » » So(tf.Master, ShouldEqual, "Chromium")
57 » » » })
58
59 » » » Convey("fetch data from multiple DataEntrys", func() {
60 » » » » So(tf1.GetData(c), ShouldBeNil)
61 » » » » b, err := ioutil.ReadAll(tf1.Data)
62 » » » » So(err, ShouldBeNil)
63 » » » » So(string(b), ShouldResemble, "hello, world")
64 » » » })
54 }) 65 })
55 66
56 » » Convey("Should fetch data from multiple DataEntries", func() { 67 » » Convey("Put", func() {
57 » » » So(tf1.GetData(c), ShouldBeNil) 68 » » » Convey("puts and retrieves DataEntry", func() {
58 » » » b, err := ioutil.ReadAll(tf1.Data) 69 » » » » data, err := ioutil.ReadFile(filepath.Join("test data", "results.json"))
59 » » » So(err, ShouldBeNil) 70 » » » » So(err, ShouldBeNil)
60 » » » So(string(b), ShouldResemble, "hello, world") 71 » » » » tf := TestFile{
72 » » » » » ID: 1,
73 » » » » » Data: bytes.NewReader(data),
74 » » » » }
75 » » » » So(tf.PutData(c), ShouldBeNil)
76 » » » » So(ds.Put(&tf), ShouldBeNil)
77
78 » » » » ds.Testable().CatchupIndexes()
79
80 » » » » tf = TestFile{ID: 1}
81 » » » » So(ds.Get(&tf), ShouldBeNil)
82 » » » » So(tf.ID, ShouldEqual, 1)
83 » » » » So(tf.GetData(c), ShouldBeNil)
84 » » » » b, err := ioutil.ReadAll(tf.Data)
85 » » » » So(err, ShouldBeNil)
86 » » » » So(b, ShouldResemble, data)
87 » » » })
88
89 » » » Convey("PutData updates DataKeys and OldDataKeys", func( ) {
90 » » » » tf := TestFile{
91 » » » » » ID: 1,
92 » » » » » Data: bytes.NewReader([]byte(`{"hello":" world"}`)),
93 » » » » }
94 » » » » So(tf.PutData(c), ShouldBeNil)
95 » » » » So(tf.DataKeys, ShouldNotBeNil)
96 » » » » So(ds.Put(&tf), ShouldBeNil)
97
98 » » » » k := make([]*datastore.Key, len(tf.DataKeys))
99 » » » » copy(k, tf.DataKeys)
100 » » » » tf.Data = bytes.NewReader([]byte(`{"new":"data"} `))
101 » » » » So(tf.PutData(c), ShouldBeNil)
102 » » » » So(tf.OldDataKeys, ShouldResemble, k)
103 » » » » So(ds.Put(&tf), ShouldBeNil)
104
105 » » » » Convey("OldDataKeys referenced DataEntry still e xists", func() {
106 » » » » » ds.Testable().CatchupIndexes()
107
108 » » » » » tmp := TestFile{DataKeys: k}
109 » » » » » So(tmp.GetData(c), ShouldBeNil)
110 » » » » » b, err := ioutil.ReadAll(tmp.Data)
111 » » » » » So(err, ShouldBeNil)
112 » » » » » So(b, ShouldResemble, []byte(`{"hello":" world"}`))
113 » » » » })
114 » » » })
61 }) 115 })
62 }) 116 })
63 } 117 }
OLDNEW
« no previous file with comments | « go/src/infra/appengine/test-results/model/test_file.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698