Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Test calling DiffLocks will one or more empty locks
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs committed Apr 14, 2017
1 parent fdda10c commit a796e9d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lockdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,54 @@ func TestDiffLocks_ModifyHash(t *testing.T) {
t.Fatalf("Expected diff.HashDiff to be '%s', got '%s'", want, got)
}
}

func TestDiffLocks_EmptyInitialLock(t *testing.T) {
h2, _ := hex.DecodeString("abc123")
l2 := safeLock{
h: h2,
p: []LockedProject{
{pi: ProjectIdentifier{ProjectRoot: "github.com/foo/bar"}, v: NewVersion("v1.0.0")},
},
}

diff := DiffLocks(nil, l2)

wantHash := "+ abc123"
gotHash := diff.HashDiff.String()
if gotHash != wantHash {
t.Fatalf("Expected diff.HashDiff to be '%s', got '%s'", wantHash, gotHash)
}

if len(diff.Add) != 1 {
t.Fatalf("Expected diff.Add to contain 1 project, got %d", len(diff.Add))
}
}

func TestDiffLocks_EmptyFinalLock(t *testing.T) {
h1, _ := hex.DecodeString("abc123")
l1 := safeLock{
h: h1,
p: []LockedProject{
{pi: ProjectIdentifier{ProjectRoot: "github.com/foo/bar"}, v: NewVersion("v1.0.0")},
},
}

diff := DiffLocks(l1, nil)

wantHash := "- abc123"
gotHash := diff.HashDiff.String()
if gotHash != wantHash {
t.Fatalf("Expected diff.HashDiff to be '%s', got '%s'", wantHash, gotHash)
}

if len(diff.Remove) != 1 {
t.Fatalf("Expected diff.Remove to contain 1 project, got %d", len(diff.Remove))
}
}

func TestDiffLocks_EmptyLocks(t *testing.T) {
diff := DiffLocks(nil, nil)
if diff != nil {
t.Fatal("Expected the diff to be empty")
}
}

0 comments on commit a796e9d

Please sign in to comment.