Skip to content

Commit

Permalink
💪 Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Omochice committed Oct 6, 2021
1 parent 05e3e80 commit 2f009cc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -57,3 +60,25 @@ func TestLoadsettings(t *testing.T) {
t.Fatalf(errorText+"\nInputed: %#v", setting)
}
}

func Exists(filename string) bool {
_, err := os.Stat(filename)
return err == nil
}

func TestInitializeConfigFile(t *testing.T) {
dir, err := ioutil.TempDir("", "example")
if err != nil {
t.Fatalf("Error occurred in iotuil.Tempdir")
}
defer os.RemoveAll(dir)
p := filepath.Join(dir, "config.json")

// will success
if err := InitializeConfigFile(p); err != nil {
t.Fatalf("The function should not occur error\nActual: %s", err.Error())
}
if !Exists(p) {
t.Fatalf("The function should make configfile(%s)", p)
}
}

0 comments on commit 2f009cc

Please sign in to comment.