| // Copyright 2020 The Fuchsia 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 main |
| |
| import ( |
| "reflect" |
| "testing" |
| |
| buildbucketpb "go.chromium.org/luci/buildbucket/proto" |
| ) |
| |
| func TestNewBuilderID(t *testing.T) { |
| t.Parallel() |
| tests := []struct { |
| input string |
| expected *buildbucketpb.BuilderID |
| expectedErr bool |
| }{ |
| { |
| input: "foo-project/bar-bucket/baz-builder", |
| expected: &buildbucketpb.BuilderID{ |
| Project: "foo-project", |
| Bucket: "bar-bucket", |
| Builder: "baz-builder", |
| }, |
| expectedErr: false, |
| }, |
| { |
| input: "invalid-input", |
| expected: nil, |
| expectedErr: true, |
| }, |
| { |
| input: "foo-project/bar-bucket/baz-builder/extra", |
| expected: nil, |
| expectedErr: true, |
| }, |
| } |
| for _, test := range tests { |
| builderID, err := newBuilderID(test.input) |
| if err == nil { |
| if test.expectedErr { |
| t.Fatalf("expected error, got nil") |
| } |
| } else if !test.expectedErr { |
| t.Fatalf("got unexpected error: %s", err) |
| } |
| if !reflect.DeepEqual(test.expected, builderID) { |
| t.Fatalf("expected %s, got %s", test.expected, builderID) |
| } |
| } |
| } |