mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 20:55:47 +00:00
test: add config to tests
This commit is contained in:
@@ -38,10 +38,25 @@ const author_data = `
|
||||
}
|
||||
}`
|
||||
|
||||
|
||||
const config_data = `[settings]
|
||||
author_file = "author_file_test"
|
||||
starting_scope = "git"
|
||||
editor = "built-in"
|
||||
`
|
||||
|
||||
var envVar = os.Getenv("author_file")
|
||||
|
||||
func setup() {
|
||||
// setup test data
|
||||
err := os.WriteFile("test_config.toml", []byte(config_data), 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
os.Setenv("COCOMMIT_CONFIG", "test_config.toml")
|
||||
|
||||
utils.Find_authorfile()
|
||||
os.WriteFile("author_file_test", []byte(author_data), 0644)
|
||||
os.Setenv("author_file", "author_file_test")
|
||||
}
|
||||
@@ -50,6 +65,7 @@ func teardown() {
|
||||
// remove test data
|
||||
os.Remove("author_file_test")
|
||||
os.Setenv("author_file", envVar)
|
||||
os.Remove("test_config.toml")
|
||||
}
|
||||
|
||||
// Author tests BEGIN
|
||||
@@ -128,10 +144,12 @@ func Test_FindAuthorFilePanic(t *testing.T) {
|
||||
originalAuthorFile := os.Getenv("author_file")
|
||||
originalHome := os.Getenv("HOME")
|
||||
orignalXDG := os.Getenv("XDG_CONFIG_HOME")
|
||||
originalAuthorFile_Config := utils.ConfigVar.Settings.AuthorFile
|
||||
|
||||
// Test Find_authorfile panic
|
||||
defer func() {
|
||||
// Reset environment variables
|
||||
utils.ConfigVar.Settings.AuthorFile = originalAuthorFile_Config
|
||||
os.Setenv("author_file", originalAuthorFile)
|
||||
os.Setenv("HOME", originalHome)
|
||||
os.Setenv("XDG_CONFIG_HOME", orignalXDG)
|
||||
@@ -143,6 +161,7 @@ func Test_FindAuthorFilePanic(t *testing.T) {
|
||||
|
||||
// Set environment variables to empty strings
|
||||
// to trigger the panic
|
||||
utils.ConfigVar.Settings.AuthorFile = ""
|
||||
os.Setenv("author_file", "")
|
||||
os.Setenv("HOME", "")
|
||||
os.Setenv("XDG_CONFIG_HOME", "")
|
||||
|
||||
Reference in New Issue
Block a user