портирован код из старого репозитория https://di9.ru/git/Voomra/Conventional-Commits
36 lines
637 B
Go
36 lines
637 B
Go
package commitlint
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadCommitMessage(t *testing.T) {
|
|
createTmpFile := func() string {
|
|
tmpFile, err := os.CreateTemp("", "COMMIT_EDITMSG")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer func(tmpFile *os.File) {
|
|
_ = tmpFile.Close()
|
|
}(tmpFile)
|
|
|
|
_, err = tmpFile.WriteString("Line 1\nLine 2\nLine 3")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return tmpFile.Name()
|
|
}
|
|
|
|
exceptedContent := []string{"Line 1", "Line 2", "Line 3"}
|
|
|
|
message, err := ReadCommitMessage(createTmpFile())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
assert.Equal(t, exceptedContent, message)
|
|
}
|