| // Copyright 2019 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 manifest |
| |
| import ( |
| "strings" |
| "testing" |
| ) |
| |
| func TestResolveRecipesProject(t *testing.T) { |
| t.Parallel() |
| |
| tests := []struct { |
| projectsXML string |
| expectedRemote string |
| expectedRevision string |
| expectErr bool |
| }{ |
| { |
| projectsXML: ` |
| <manifest> |
| <projects> |
| <project remote="https://fuchsia.googlesource.com/infra/recipes" |
| path="a/b/c" |
| revision="foo"/> |
| </projects> |
| </manifest> |
| `, |
| expectedRemote: "https://fuchsia.googlesource.com/infra/recipes", |
| expectedRevision: "foo", |
| }, |
| { |
| projectsXML: ` |
| <manifest> |
| <projects> |
| <project remote="https://fuchsia.googlesource.com/dunno" |
| path="a/b/c" |
| revision="foo"/> |
| <project remote="https://fuchsia.googlesource.com/infra/recipes" |
| path="a/b/c" |
| revision="bar"/> |
| <project remote="https://fuchsia.googlesource.com/other" |
| path="a/b/c" |
| revision="baz"/> |
| </projects> |
| </manifest> |
| `, |
| expectedRemote: "https://fuchsia.googlesource.com/infra/recipes", |
| expectedRevision: "bar", |
| }, |
| { |
| projectsXML: ` |
| <manifest> |
| <projects> |
| <project remote="https://fuchsia.googlesource.com/dunno" |
| path="a/b/c" |
| revision="foo"/> |
| </projects> |
| </manifest> |
| `, |
| expectErr: true, |
| }, |
| } |
| |
| for _, test := range tests { |
| proj, err := ResolveRecipesProject(strings.NewReader(test.projectsXML), "https://fuchsia.googlesource.com/infra/recipes") |
| if err == nil { |
| if test.expectErr { |
| t.Fatalf("expected error, got nil") |
| } |
| if proj.Remote != test.expectedRemote { |
| t.Fatalf("project %q does not match expected %q", proj.Remote, test.expectedRemote) |
| } |
| if proj.Revision != test.expectedRevision { |
| t.Fatalf("revision %q does not match expected %q", proj.Revision, test.expectedRevision) |
| } |
| } else if !test.expectErr { |
| t.Fatalf("got unexpected error: %s", err) |
| } |
| } |
| } |