Assert functions for test harness
This CL adds various assert functions to the harness that let clients
assert on certain properties of the harness setup.
I'd like to note that repo_harness is intended to be fully generic and
not dependent on the structure of the CrOS project. In subsequent CLs I will
introduce something like cros_repo_harness, which will include cros-specific
assert functions.
TEST=run_tests.sh
BUG=chromium:980346
Change-Id: I0cf2cf63f034ee38df092a2064967c14a25672db
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/infra/go/+/1709529
Commit-Queue: Jack Neus <jackneus@google.com>
Tested-by: Jack Neus <jackneus@google.com>
Reviewed-by: Evan Hernandez <evanhernandez@chromium.org>
diff --git a/internal/git/git_test.go b/internal/git/git_test.go
index 4c7ada3..057b168 100644
--- a/internal/git/git_test.go
+++ b/internal/git/git_test.go
@@ -98,6 +98,27 @@
assert.DeepEqual(t, expectedMatches, branches)
}
+func TestMatchBranchNameWithNamespace_success(t *testing.T) {
+ fakeGitRepo := "top-secret-project"
+ fakeGitData := "e9cb56bd9af9365b43f82cecf28cc76d49df1f72 refs/changes/foo\n" +
+ "f9c1bb630f4475058d4a9db4aea52fc89d8f7b0d refs/changes/bar\n" +
+ "2102915989de21d9251c11f0a7b5307e175e7677 refs/heads/foobar\n" +
+ "04975f9439ff75502b33d9491155692736e05b07 refs/heads/baz\n"
+
+ CommandRunnerImpl = cmd.FakeCommandRunner{
+ ExpectedCmd: []string{"git", "ls-remote", fakeGitRepo},
+ ExpectedDir: fakeGitRepo,
+ Stdout: fakeGitData,
+ }
+
+ expectedMatches := []string{"foobar"}
+ pattern := regexp.MustCompile("FOO")
+ namespace := regexp.MustCompile("refs/heads/")
+ branches, err := MatchBranchNameWithNamespace(fakeGitRepo, pattern, namespace)
+ assert.NilError(t, err)
+ assert.DeepEqual(t, expectedMatches, branches)
+}
+
func TestGetRepoRevision(t *testing.T) {
sha := "6446dfef4b55689046395c2db7ba7c35377927fe"
CommandRunnerImpl = cmd.FakeCommandRunner{