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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/appengine/test-results/model/test_file_test.go
diff --git a/go/src/infra/appengine/test-results/model/test_file_test.go b/go/src/infra/appengine/test-results/model/test_file_test.go
index ed5f64855da01c4f90da1460e6232b5806e56194..d18f883a7999a0b0d33382a224adf478d402e0a5 100644
--- a/go/src/infra/appengine/test-results/model/test_file_test.go
+++ b/go/src/infra/appengine/test-results/model/test_file_test.go
@@ -1,7 +1,9 @@
package model
import (
+ "bytes"
"io/ioutil"
+ "path/filepath"
"testing"
"github.com/luci/gae/impl/memory"
@@ -21,43 +23,95 @@ func TestTestFile(t *testing.T) {
So(err, ShouldBeNil)
ds.Testable().AddIndexes(testFileIdx...)
- dataEntries := []DataEntry{
- {Data: []byte("hello, "), ID: 142},
- {Data: []byte("world"), ID: 199},
- }
-
- for _, de := range dataEntries {
- So(ds.Put(&de), ShouldBeNil)
- }
-
- dataKeys := make([]*datastore.Key, len(dataEntries))
- for i, de := range dataEntries {
- dataKeys[i] = ds.KeyForObj(&de)
- }
-
- tf1 := TestFile{
- ID: 1,
- Name: "full_results.json",
- Master: "Chromium",
- DataKeys: dataKeys,
- }
-
- So(ds.Put(&tf1), ShouldBeNil)
- ds.Testable().CatchupIndexes()
-
- Convey("Should get an existing TestFile by ID", func() {
- tf := TestFile{ID: 1}
- So(ds.Get(&tf), ShouldBeNil)
- So(tf.ID, ShouldEqual, 1)
- So(tf.Name, ShouldEqual, "full_results.json")
- So(tf.Master, ShouldEqual, "Chromium")
+ Convey("Get", func() {
+ dataEntries := []DataEntry{
+ {Data: []byte("hello, "), ID: 142},
+ {Data: []byte("world"), ID: 199},
+ }
+
+ for _, de := range dataEntries {
+ So(ds.Put(&de), ShouldBeNil)
+ }
+
+ dataKeys := make([]*datastore.Key, len(dataEntries))
+ for i, de := range dataEntries {
+ dataKeys[i] = ds.KeyForObj(&de)
+ }
+
+ tf1 := TestFile{
+ ID: 1,
+ Name: "full_results.json",
+ Master: "Chromium",
+ DataKeys: dataKeys,
+ }
+
+ So(ds.Put(&tf1), ShouldBeNil)
+ ds.Testable().CatchupIndexes()
+
+ Convey("get an existing TestFile by ID", func() {
+ tf := TestFile{ID: 1}
+ So(ds.Get(&tf), ShouldBeNil)
+ So(tf.ID, ShouldEqual, 1)
+ So(tf.Name, ShouldEqual, "full_results.json")
+ So(tf.Master, ShouldEqual, "Chromium")
+ })
+
+ Convey("fetch data from multiple DataEntrys", func() {
+ So(tf1.GetData(c), ShouldBeNil)
+ b, err := ioutil.ReadAll(tf1.Data)
+ So(err, ShouldBeNil)
+ So(string(b), ShouldResemble, "hello, world")
+ })
})
- Convey("Should fetch data from multiple DataEntries", func() {
- So(tf1.GetData(c), ShouldBeNil)
- b, err := ioutil.ReadAll(tf1.Data)
- So(err, ShouldBeNil)
- So(string(b), ShouldResemble, "hello, world")
+ Convey("Put", func() {
+ Convey("puts and retrieves DataEntry", func() {
+ data, err := ioutil.ReadFile(filepath.Join("testdata", "results.json"))
+ So(err, ShouldBeNil)
+ tf := TestFile{
+ ID: 1,
+ Data: bytes.NewReader(data),
+ }
+ So(tf.PutData(c), ShouldBeNil)
+ So(ds.Put(&tf), ShouldBeNil)
+
+ ds.Testable().CatchupIndexes()
+
+ tf = TestFile{ID: 1}
+ So(ds.Get(&tf), ShouldBeNil)
+ So(tf.ID, ShouldEqual, 1)
+ So(tf.GetData(c), ShouldBeNil)
+ b, err := ioutil.ReadAll(tf.Data)
+ So(err, ShouldBeNil)
+ So(b, ShouldResemble, data)
+ })
+
+ Convey("PutData updates DataKeys and OldDataKeys", func() {
+ tf := TestFile{
+ ID: 1,
+ Data: bytes.NewReader([]byte(`{"hello":"world"}`)),
+ }
+ So(tf.PutData(c), ShouldBeNil)
+ So(tf.DataKeys, ShouldNotBeNil)
+ So(ds.Put(&tf), ShouldBeNil)
+
+ k := make([]*datastore.Key, len(tf.DataKeys))
+ copy(k, tf.DataKeys)
+ tf.Data = bytes.NewReader([]byte(`{"new":"data"}`))
+ So(tf.PutData(c), ShouldBeNil)
+ So(tf.OldDataKeys, ShouldResemble, k)
+ So(ds.Put(&tf), ShouldBeNil)
+
+ Convey("OldDataKeys referenced DataEntry still exists", func() {
+ ds.Testable().CatchupIndexes()
+
+ tmp := TestFile{DataKeys: k}
+ So(tmp.GetData(c), ShouldBeNil)
+ b, err := ioutil.ReadAll(tmp.Data)
+ So(err, ShouldBeNil)
+ So(b, ShouldResemble, []byte(`{"hello":"world"}`))
+ })
+ })
})
})
}
« 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