github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/review/git-review/branch_test.go (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import "testing"
     8  
     9  func TestCurrentBranch(t *testing.T) {
    10  	gt := newGitTest(t)
    11  	defer gt.done()
    12  
    13  	t.Logf("on master")
    14  	checkCurrentBranch(t, "master", "origin/master", false, false, "", "")
    15  
    16  	t.Logf("on newbranch")
    17  	trun(t, gt.client, "git", "checkout", "-b", "newbranch")
    18  	checkCurrentBranch(t, "newbranch", "origin/master", true, false, "", "")
    19  
    20  	t.Logf("making change")
    21  	write(t, gt.client+"/file", "i made a change")
    22  	trun(t, gt.client, "git", "commit", "-a", "-m", "My change line.\n\nChange-Id: I0123456789abcdef0123456789abcdef\n")
    23  	checkCurrentBranch(t, "newbranch", "origin/master", true, true, "I0123456789abcdef0123456789abcdef", "My change line.")
    24  
    25  	t.Logf("on dev.branch")
    26  	trun(t, gt.client, "git", "checkout", "-t", "-b", "dev.branch", "origin/dev.branch")
    27  	checkCurrentBranch(t, "dev.branch", "origin/dev.branch", false, false, "", "")
    28  
    29  	t.Logf("on newdev")
    30  	trun(t, gt.client, "git", "checkout", "-t", "-b", "newdev", "origin/dev.branch")
    31  	checkCurrentBranch(t, "newdev", "origin/dev.branch", true, false, "", "")
    32  
    33  	t.Logf("making change")
    34  	write(t, gt.client+"/file", "i made another change")
    35  	trun(t, gt.client, "git", "commit", "-a", "-m", "My other change line.\n\nChange-Id: I1123456789abcdef0123456789abcdef\n")
    36  	checkCurrentBranch(t, "newdev", "origin/dev.branch", true, true, "I1123456789abcdef0123456789abcdef", "My other change line.")
    37  }
    38  
    39  func checkCurrentBranch(t *testing.T, name, origin string, isLocal, hasPending bool, changeID, subject string) {
    40  	b := CurrentBranch()
    41  	if b.Name != name {
    42  		t.Errorf("b.Name = %q, want %q", b.Name, name)
    43  	}
    44  	if x := b.OriginBranch(); x != origin {
    45  		t.Errorf("b.OriginBranch() = %q, want %q", x, origin)
    46  	}
    47  	if x := b.IsLocalOnly(); x != isLocal {
    48  		t.Errorf("b.IsLocalOnly() = %v, want %v", x, isLocal)
    49  	}
    50  	if x := b.HasPendingCommit(); x != hasPending {
    51  		t.Errorf("b.HasPendingCommit() = %v, want %v", x, isLocal)
    52  	}
    53  	if x := b.ChangeID(); x != changeID {
    54  		t.Errorf("b.ChangeID() = %q, want %q", x, changeID)
    55  	}
    56  	if x := b.Subject(); x != subject {
    57  		t.Errorf("b.Subject() = %q, want %q", x, subject)
    58  	}
    59  }