diff --git a/src/cmd/tui/tui_test.go b/src/cmd/tui/tui_test.go index 69f627d..c4286f8 100644 --- a/src/cmd/tui/tui_test.go +++ b/src/cmd/tui/tui_test.go @@ -38,7 +38,14 @@ const author_data = ` } }` +const config_data = `[settings] +author_file = "author_file_test" +starting_scope = "git" +editor = "built-in" +` + var envVar string +var configVar string func setup() { // setup test data @@ -49,6 +56,14 @@ func setup() { os.Setenv("author_file", "author_file_test") envVar = os.Getenv("author_file") + err = os.WriteFile("test_config.toml", []byte(config_data), 0644) + if err != nil { + panic(err) + } + + os.Setenv("COCOMMIT_CONFIG", "test_config.toml") + configVar = os.Getenv("COCOMMIT_CONFIG") + utils.Define_users("author_file_test") } @@ -56,6 +71,7 @@ func teardown() { // remove test data os.Remove("author_file_test") os.Setenv("author_file", envVar) + os.Remove("test_config.toml") } func keyPress(tm *teatest.TestModel, key string) { @@ -610,8 +626,8 @@ func Test_ScopesLocal(t *testing.T) { t.Errorf("Expected model, got %T", fm) } - if m.scope!= local_scope { - t.Errorf("Expected scope to be %v, got %v", local_scope, m.scope) + if m.scope!= mixed_scope { + t.Errorf("Expected scope to be %v, got %v", mixed_scope, m.scope) } } @@ -634,8 +650,8 @@ func Test_ScopesMixed(t *testing.T) { t.Errorf("Expected model, got %T", fm) } - if m.scope != mixed_scope { - t.Errorf("Expected scope to be %v, got %v", mixed_scope, m.scope) + if m.scope != local_scope { + t.Errorf("Expected scope to be %v, got %v", local_scope, m.scope) } } diff --git a/src/cmd/utils/util_test.go b/src/cmd/utils/util_test.go index 3418f69..8b392c4 100644 --- a/src/cmd/utils/util_test.go +++ b/src/cmd/utils/util_test.go @@ -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", "")