blob: b4eef792cc47d4a6f3bda33f8e76a8378efdc5a9 [file] [log] [blame]
Jack Neus08ccd452019-08-13 09:35:41 -06001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Sean Abraham47cc5852020-06-30 09:32:41 -06004
Sean Abrahamc2c5a6a2020-06-23 17:54:41 -06005package branch
Jack Neus08ccd452019-08-13 09:35:41 -06006
7import (
Julio Hurtado516392f2020-11-12 20:19:35 +00008 "go.chromium.org/chromiumos/infra/go/internal/cmd"
9 "go.chromium.org/chromiumos/infra/go/internal/git"
Jack Neus08ccd452019-08-13 09:35:41 -060010 "go.chromium.org/chromiumos/infra/go/internal/repo"
11 "gotest.tools/assert"
Julio Hurtado516392f2020-11-12 20:19:35 +000012 "testing"
Jack Neus08ccd452019-08-13 09:35:41 -060013)
14
15func TestProjectFetchUrl(t *testing.T) {
Sean Abrahamc2c5a6a2020-06-23 17:54:41 -060016 WorkingManifest = repo.Manifest{
Jack Neus08ccd452019-08-13 09:35:41 -060017 Remotes: []repo.Remote{
18 {Name: "remote", Fetch: "file:///tmp/path/to/remote"},
19 },
20 Projects: []repo.Project{
21 {Path: "foo/bar/project", Name: "foo/bar/project", RemoteName: "remote"},
22 },
23 }
Sean Abrahamc2c5a6a2020-06-23 17:54:41 -060024 url, err := ProjectFetchUrl("foo/bar/project")
Jack Neus08ccd452019-08-13 09:35:41 -060025 assert.NilError(t, err)
26 assert.Equal(t, url, "file:///tmp/path/to/remote/foo/bar/project")
27}
Julio Hurtado516392f2020-11-12 20:19:35 +000028
29func TestGetProjectCheckoutFromUrl(t *testing.T) {
30 git.CommandRunnerImpl = &cmd.FakeCommandRunnerMulti{
31 CommandRunners: []cmd.FakeCommandRunner{
32 {
33 ExpectedDir: "",
34 ExpectedCmd: []string{"git", "init"},
35 },
36 {
37 ExpectedDir: "",
38 ExpectedCmd: []string{"git", "remote", "add", "origin", "localhost"},
39 },
40 {
41 ExpectedDir: "",
42 ExpectedCmd: []string{"git", "fetch", "origin"},
43 },
44 {
45 ExpectedDir: "",
Mike Frysingerdfb710a2021-02-12 23:26:59 -050046 ExpectedCmd: []string{"git", "ls-remote", "-q", "--symref", "--exit-code", "origin", "HEAD"},
47 Stdout: "ref: refs/heads/mamama\tHEAD\n5f6803b100bb3cd0f534e96e88c91373e8ed1c44\tHEAD\n",
Julio Hurtado516392f2020-11-12 20:19:35 +000048 },
49 {
50 ExpectedDir: "",
Mike Frysingerdfb710a2021-02-12 23:26:59 -050051 ExpectedCmd: []string{"git", "checkout", "mamama"},
Julio Hurtado516392f2020-11-12 20:19:35 +000052 },
53 },
54 }
55
56 _, err := getProjectCheckoutFromUrl("localhost", nil)
57
58 if err != nil {
59 t.Error("Error: checkout out project reason: ", err.Error())
60 return
61 }
62}