예제 #1
0
func TestLatestCommits(t *testing.T) {
	cleanTestData()
	repo := RepoLocatedAt("data/testLocation1")
	git.Init(repo.root)
	git.SetupBaselineFiles(repo.root, "a.txt")
	git.AppendFileContent(repo.root, "a.txt", "\nmonkey see.\n", "monkey do.")
	git.AddAndcommit(repo.root, "a.txt", "modified content")
	git.AppendFileContent(repo.root, "a.txt", "\nline n-1.\n", "line n.")
	git.AddAndcommit(repo.root, "a.txt", "more modified content")
	assert.NotEqual(t, git.EarliestCommit(repo.root), git.LatestCommit(repo.root)) //bad test.
}
예제 #2
0
func TestMultipleOutgoingChangesToTheSameFileAreAvailableInAdditions(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	git.AppendFileContent(repo.root, "a.txt", "New content.\n")
	git.AddAndcommit(repo.root, "a.txt", "added some new content")

	git.AppendFileContent(repo.root, "a.txt", "More new content.\n")
	git.AddAndcommit(repo.root, "a.txt", "added some more new content")

	assert.Len(t, repo.AllAdditions(), 1)
	assert.True(t, strings.HasSuffix(string(repo.AllAdditions()[0].Data), "New content.\nMore new content.\n"))
}
예제 #3
0
func TestContentOfDeletedFilesIsNotAvailableInChanges(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	git.RemoveFile(repo.root, "a.txt")
	git.AddAndcommit(repo.root, "a.txt", "Deleted this file. After all, it only had lorem-ipsum content.")
	assert.Equal(t, 0, len(repo.AllAdditions()), "There should be no additions because there only an outgoing deletion")
}
예제 #4
0
func TestDiffContainingBinaryFileChangesDoesNotBlowUp(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	exec.Command("cp", "./pixel.jpg", repo.root).Run()
	git.AddAndcommit(repo.root, "pixel.jpg", "Testing binary diff.")
	assert.Len(t, repo.AllAdditions(), 1)
	assert.Equal(t, "pixel.jpg", string(repo.AllAdditions()[0].Name))
}
예제 #5
0
func TestOutgoingContentOfModifiedFilesIsAvailableInChanges(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	git.AppendFileContent(repo.root, "a.txt", "New content.\n", "Spanning multiple lines, even.")
	git.AddAndcommit(repo.root, "a.txt", "added to lorem-ipsum content with my own stuff!")
	assert.Len(t, repo.AllAdditions(), 1)
	assert.True(t, strings.HasSuffix(string(repo.AllAdditions()[0].Data), "New content.\nSpanning multiple lines, even."))
}
예제 #6
0
func TestNewlyAddedFilesAreCountedAsChanges(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	git.CreateFileWithContents(repo.root, "h", "Hello")
	git.CreateFileWithContents(repo.root, "foo/bar/w", ", World!")
	git.AddAndcommit(repo.root, "*", "added hello world")
	assert.Len(t, repo.AllAdditions(), 2)
}
예제 #7
0
func TestOutgoingContentOfNewlyAddedFilesIsAvailableInChanges(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	git.CreateFileWithContents(repo.root, "foo/bar/w", "new contents")
	git.AddAndcommit(repo.root, "*", "added new files")

	assert.Len(t, repo.AllAdditions(), 1)
	assert.True(t, strings.HasSuffix(string(repo.AllAdditions()[0].Data), "new contents"))
}
예제 #8
0
func TestEarliestCommits(t *testing.T) {
	cleanTestData()
	repo := RepoLocatedAt("data/testLocation1")
	git.Init(repo.root)
	git.SetupBaselineFiles(repo.root, "a.txt")
	initialCommit := git.EarliestCommit(repo.root)
	git.AppendFileContent(repo.root, "a.txt", "\nmonkey see.\n", "monkey do.")
	git.AddAndcommit(repo.root, "a.txt", "modified content")
	assert.Equal(t, initialCommit, git.EarliestCommit(repo.root), "First commit is not expected to change on repo modifications")
}
예제 #9
0
func TestRemovingFilesInARepoWorks(t *testing.T) {
	cleanTestData()
	repo := RepoLocatedAt("data/testLocation1")
	git.Init(repo.root)
	git.SetupBaselineFiles(repo.root, "a.txt", "alice/bob/b.txt")
	git.RemoveFile(repo.root, "a.txt")
	assert.False(t, exists("data/testLocation1/a.txt"), "Unexpected. Deleted file a.txt still exists inside the repo")
	git.AddAndcommit(repo.root, "a.txt", "removed it")
	verifyPresenceOfGitRepoWithCommits("data/testLocation1", 2, t)
}
예제 #10
0
func TestAddingSecretKeyShouldExitOne(t *testing.T) {
	withNewTmpGitRepo(func(gitPath string) {
		git.SetupBaselineFiles(gitPath, "simple-file")
		git.CreateFileWithContents(gitPath, "private.pem", "secret")
		git.AddAndcommit(gitPath, "*", "add private key")

		exitStatus := runTalisman(gitPath, git.EarliestCommit(gitPath), git.LatestCommit(gitPath))
		assert.Equal(t, 1, exitStatus, "Expected run() to return 1 and fail as pem file was present in the repo")
	})
}
예제 #11
0
func TestEditingFilesInARepoWorks(t *testing.T) {
	cleanTestData()
	repo := RepoLocatedAt("data/testLocation1")
	git.Init(repo.root)
	git.SetupBaselineFiles(repo.root, "a.txt", "alice/bob/b.txt")
	git.AppendFileContent(repo.root, "a.txt", "\nmonkey see.\n", "monkey do.")
	content := git.FileContents(repo.root, "a.txt")
	assert.True(t, strings.HasSuffix(string(content), "monkey see.\nmonkey do."))
	git.AddAndcommit(repo.root, "a.txt", "modified content")
	verifyPresenceOfGitRepoWithCommits("data/testLocation1", 2, t)
}
예제 #12
0
func TestAdditionsReturnsEditsAndAdds(t *testing.T) {
	cleanTestData()
	_, repo := setupOriginAndClones("data/testLocation1", "data/cloneLocation")
	git.AppendFileContent(repo.root, "a.txt", "New content.\n", "Spanning multiple lines, even.")
	git.CreateFileWithContents(repo.root, "new.txt", "created contents")
	git.AddAndcommit(repo.root, "*", "added to lorem-ipsum content with my own stuff!")

	additions := repo.Additions("HEAD~1", "HEAD")
	assert.Len(t, additions, 2)
	assert.True(t, strings.HasSuffix(string(additions[0].Data), "New content.\nSpanning multiple lines, even."))
}
예제 #13
0
func TestAddingSecretKeyShouldExitZeroIfPEMFilesAreIgnored(t *testing.T) {
	withNewTmpGitRepo(func(gitPath string) {
		git.SetupBaselineFiles(gitPath, "simple-file")
		git.CreateFileWithContents(gitPath, "private.pem", "secret")
		git.CreateFileWithContents(gitPath, ".talismanignore", "*.pem")
		git.AddAndcommit(gitPath, "*", "add private key")

		exitStatus := runTalisman(gitPath, git.EarliestCommit(gitPath), git.LatestCommit(gitPath))
		assert.Equal(t, 0, exitStatus, "Expected run() to return 0 and pass as pem file was ignored")
	})
}