Ejemplo n.º 1
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)
}
Ejemplo n.º 2
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")
	})
}
Ejemplo n.º 3
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"))
}
Ejemplo n.º 4
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")
	})
}
Ejemplo n.º 5
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."))
}