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

Unified Diff: go/src/infra/monorail/validation.go

Issue 2037143002: Monorail client in Go (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: more tests Created 4 years, 6 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/monorail/pb.discovery.go ('k') | go/src/infra/monorail/validation_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/monorail/validation.go
diff --git a/go/src/infra/monorail/validation.go b/go/src/infra/monorail/validation.go
new file mode 100644
index 0000000000000000000000000000000000000000..e2448d1c1a48e9ad8e1e9d150dbc7451ca6acd94
--- /dev/null
+++ b/go/src/infra/monorail/validation.go
@@ -0,0 +1,93 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package monorail
+
+import "fmt"
+
+// Validate checks the message for errors.
+func (i *IssueRef) Validate() error {
+ if i == nil {
+ return fmt.Errorf("is nil")
+ }
+ if i.ProjectId == "" {
+ return fmt.Errorf("no projectId")
+ }
+ if i.IssueId == 0 {
+ return fmt.Errorf("no issueId")
+ }
+ return nil
+}
+
+// Validate checks the message for errors.
+func (a *AtomPerson) Validate() error {
+ if a == nil {
+ return fmt.Errorf("is nil")
+ }
+ if a.Name == "" {
+ return fmt.Errorf("no name")
+ }
+ return nil
+}
+
+// Validate checks the message for errors.
+func (i *Issue) Validate() error {
+ if i == nil {
+ return fmt.Errorf("is nil")
+ }
+ if i.Status == "" {
+ return fmt.Errorf("no status")
+ }
+ for _, ref := range i.BlockedOn {
+ if err := ref.Validate(); err != nil {
+ return fmt.Errorf("blockedOn: %s", err)
+ }
+ }
+
+ seen := map[string]struct{}{}
+ for _, cc := range i.Cc {
+ if err := cc.Validate(); err != nil {
+ return fmt.Errorf("cc: %s", err)
+ }
+ // Monorail does not like duplicates in CC list.
+ if _, saw := seen[cc.Name]; saw {
+ return fmt.Errorf("cc: duplicate %s", cc.Name)
+ }
+ seen[cc.Name] = struct{}{}
+ }
+
+ for _, c := range i.Components {
+ if c == "" {
+ return fmt.Errorf("empty component")
+ }
+ }
+
+ for _, label := range i.Labels {
+ if label == "" {
+ return fmt.Errorf("empty label")
+ }
+ }
+
+ if i.Owner != nil {
+ if err := i.Owner.Validate(); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+// Validate checks the message for errors.
+func (i *InsertIssueRequest) Validate() error {
+ if i.ProjectId == "" {
+ return fmt.Errorf("no projectId")
+ }
+ if err := i.Issue.Validate(); err != nil {
+ return fmt.Errorf("issue: %s", err)
+ }
+ if i.Issue.Id != 0 {
+ return fmt.Errorf("issue: must not have id")
+ }
+ return nil
+}
« no previous file with comments | « go/src/infra/monorail/pb.discovery.go ('k') | go/src/infra/monorail/validation_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698