[gold] Initialize types for trace comments
Change-Id: Idc8d7f61624d90c59881c82bffe4f94733355cd3
Bug: skia:6630
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/270952
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
diff --git a/golden/go/comment/comment.go b/golden/go/comment/comment.go
new file mode 100644
index 0000000..c5d3e20
--- /dev/null
+++ b/golden/go/comment/comment.go
@@ -0,0 +1,25 @@
+package comment
+
+import (
+ "context"
+
+ "go.skia.org/infra/golden/go/comment/trace"
+)
+
+// Store is an abstraction about a way to store comments.
+type Store interface {
+ // CreateComment stores the given trace.Comment. It will provide a new ID for the trace
+ // and return it as the first return parameter if successful.
+ CreateComment(context.Context, trace.Comment) (trace.ID, error)
+
+ // DeleteComment deletes a trace.Comment with a given id. Implementations may return an
+ // error if it does not exist.
+ DeleteComment(ctx context.Context, id trace.ID) error
+
+ // UpdateComment updates a stored trace.Comment with the given values. It will not
+ // replace the CreatedBy or CreatedTS, but everything else can be mutated.
+ UpdateComment(context.Context, trace.Comment) error
+
+ // ListComments returns all trace.Comment comments in the store.
+ ListComments(context.Context) ([]trace.Comment, error)
+}
diff --git a/golden/go/comment/mocks/Store.go b/golden/go/comment/mocks/Store.go
new file mode 100644
index 0000000..09e138b
--- /dev/null
+++ b/golden/go/comment/mocks/Store.go
@@ -0,0 +1,87 @@
+// Code generated by mockery v1.0.0. DO NOT EDIT.
+
+package mocks
+
+import (
+ context "context"
+
+ mock "github.com/stretchr/testify/mock"
+ trace "go.skia.org/infra/golden/go/comment/trace"
+)
+
+// Store is an autogenerated mock type for the Store type
+type Store struct {
+ mock.Mock
+}
+
+// CreateComment provides a mock function with given fields: _a0, _a1
+func (_m *Store) CreateComment(_a0 context.Context, _a1 trace.Comment) (trace.ID, error) {
+ ret := _m.Called(_a0, _a1)
+
+ var r0 trace.ID
+ if rf, ok := ret.Get(0).(func(context.Context, trace.Comment) trace.ID); ok {
+ r0 = rf(_a0, _a1)
+ } else {
+ r0 = ret.Get(0).(trace.ID)
+ }
+
+ var r1 error
+ if rf, ok := ret.Get(1).(func(context.Context, trace.Comment) error); ok {
+ r1 = rf(_a0, _a1)
+ } else {
+ r1 = ret.Error(1)
+ }
+
+ return r0, r1
+}
+
+// DeleteComment provides a mock function with given fields: ctx, id
+func (_m *Store) DeleteComment(ctx context.Context, id trace.ID) error {
+ ret := _m.Called(ctx, id)
+
+ var r0 error
+ if rf, ok := ret.Get(0).(func(context.Context, trace.ID) error); ok {
+ r0 = rf(ctx, id)
+ } else {
+ r0 = ret.Error(0)
+ }
+
+ return r0
+}
+
+// ListComments provides a mock function with given fields: _a0
+func (_m *Store) ListComments(_a0 context.Context) ([]trace.Comment, error) {
+ ret := _m.Called(_a0)
+
+ var r0 []trace.Comment
+ if rf, ok := ret.Get(0).(func(context.Context) []trace.Comment); ok {
+ r0 = rf(_a0)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]trace.Comment)
+ }
+ }
+
+ var r1 error
+ if rf, ok := ret.Get(1).(func(context.Context) error); ok {
+ r1 = rf(_a0)
+ } else {
+ r1 = ret.Error(1)
+ }
+
+ return r0, r1
+}
+
+// UpdateComment provides a mock function with given fields: _a0, _a1
+func (_m *Store) UpdateComment(_a0 context.Context, _a1 trace.Comment) error {
+ ret := _m.Called(_a0, _a1)
+
+ var r0 error
+ if rf, ok := ret.Get(0).(func(context.Context, trace.Comment) error); ok {
+ r0 = rf(_a0, _a1)
+ } else {
+ r0 = ret.Error(0)
+ }
+
+ return r0
+}
diff --git a/golden/go/comment/mocks/generate.go b/golden/go/comment/mocks/generate.go
new file mode 100644
index 0000000..d8b3f46
--- /dev/null
+++ b/golden/go/comment/mocks/generate.go
@@ -0,0 +1,3 @@
+package mocks
+
+//go:generate mockery -name Store -dir ../ -output .
diff --git a/golden/go/comment/trace/trace.go b/golden/go/comment/trace/trace.go
new file mode 100644
index 0000000..7a8c2b7
--- /dev/null
+++ b/golden/go/comment/trace/trace.go
@@ -0,0 +1,29 @@
+package trace
+
+import (
+ "time"
+
+ "go.skia.org/infra/go/paramtools"
+)
+
+// Comment represents a comment made on a Gold trace.
+type Comment struct {
+ // ID uniquely represents a comment. It will be provided by the Store upon creation.
+ ID ID
+ // CreatedBy is the email address of the user who created this trace comment.
+ CreatedBy string
+ // UpdatedBy is the email address of the user who most recently updated this trace comment.
+ UpdatedBy string
+ // CreatedTS is when the comment was created.
+ CreatedTS time.Time
+ // UpdatedTS is when the comment was updated.
+ UpdatedTS time.Time
+ // Comment is an arbitrary string. There can be special rules that only the frontend cares about
+ // (e.g. some markdown or coordinates).
+ Comment string
+ // QueryToMatch represents which traces this trace comment should apply to.
+ QueryToMatch paramtools.ParamSet
+}
+
+// ID represents a unique identifier to a comment for the purposes of retrieval.
+type ID string