mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
added test to increase coverage #31
This commit is contained in:
parent
4de994e030
commit
42e69ac821
1 changed files with 50 additions and 0 deletions
|
|
@ -1,7 +1,10 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/jesseduffield/yaml"
|
||||
)
|
||||
|
||||
func TestDockerComposeCommandNoFiles(t *testing.T) {
|
||||
|
|
@ -48,3 +51,50 @@ func TestDockerComposeCommandMultipleFiles(t *testing.T) {
|
|||
t.Fatalf("Expected %s but got %s", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWritingToConfigFile(t *testing.T) {
|
||||
//init the AppConfig
|
||||
emptyComposeFiles := []string{}
|
||||
conf, err := NewAppConfig("name", "version", "commit", "date", "buildSource", false, emptyComposeFiles, "projectDir")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
|
||||
testFn := func(ac *AppConfig, newReportingValue string, t *testing.T) {
|
||||
updateFn := func(uc *UserConfig) error {
|
||||
uc.Reporting = newReportingValue
|
||||
return nil
|
||||
}
|
||||
|
||||
err = ac.WriteToUserConfig(updateFn)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(ac.ConfigFilename(), os.O_RDONLY, 0660)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
|
||||
sampleUC := UserConfig{}
|
||||
err = yaml.NewDecoder(file).Decode(&sampleUC)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %s", err)
|
||||
}
|
||||
|
||||
if sampleUC.Reporting != newReportingValue {
|
||||
t.Fatalf("Got %s, Expected %s\n", sampleUC.Reporting, newReportingValue)
|
||||
}
|
||||
}
|
||||
|
||||
// insert value into an empty file
|
||||
testFn(conf, "on", t)
|
||||
|
||||
// modifying an existing file that already has 'Reporting'
|
||||
testFn(conf, "off", t)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue