package config import ( "os" "path/filepath" "testing" ) func TestLoadConfigNonExistent(t *testing.T) { err := LoadConfig(filepath.Join("..", "..", "test", "data", "doesnotexist.toml")) if err != nil { t.Errorf("Cannot write defaults, error: %+v", err) } } func TestWriteConfig(t *testing.T) { C.Twitter.AccessKey = "§OneNiceKey" C.Twitter.AccessSecret = "SuperNiceSecret" C.Twitter.ConsumerKey = "ConsumeMe" C.Twitter.ConsumerSecret = "EatASecret" err := WriteConfig(filepath.Join("..", "..", "test", "data", "doesnotexist.toml")) if err != nil { t.Errorf("Could not write config, got error: %+v", err) } } func TestLoadConfig(t *testing.T) { C = Config{} err := LoadConfig(filepath.Join("..", "..", "test", "data", "doesnotexist.toml")) if err != nil { t.Errorf("Cannot read config, error: %+v", err) } if C.Twitter.AccessKey != "§OneNiceKey" || C.Twitter.AccessSecret != "SuperNiceSecret" || C.Twitter.ConsumerKey != "ConsumeMe" || C.Twitter.ConsumerSecret != "EatASecret" { t.Errorf("Could not read config, entries wrong") } t.Cleanup(CleanupConfigTest) } func CleanupConfigTest() { os.Remove(filepath.Join("..", "..", "test", "data", "doesnotexist.toml")) }