Skip to content

Commit

Permalink
adjust testing for win
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Oct 9, 2023
1 parent 22b7538 commit 44a39dc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
)

Expand All @@ -29,6 +30,10 @@ func TestLoadConfigFiles(t *testing.T) {
}

if localConf != nil {
if runtime.GOOS == "windows" {
strings.ReplaceAll(*localConf, "local_root: /", "local_root: D:/")
}

err := ioutil.WriteFile(
filepath.Join(tempdir, "blogsync.yaml"), []byte(*localConf), 0755)
if err != nil {
Expand All @@ -38,6 +43,9 @@ func TestLoadConfigFiles(t *testing.T) {
}

if globalConf != nil {
if runtime.GOOS == "windows" {
strings.ReplaceAll(*globalConf, "local_root: /", "local_root: D:/")
}
globalConfFile := filepath.Join(tempdir, ".config", "blogsync", "config.yaml")
err := os.MkdirAll(filepath.Dir(globalConfFile), 0755)
if err != nil {
Expand Down Expand Up @@ -208,6 +216,9 @@ func TestLoadConfigFiles(t *testing.T) {
}
out := conf.Get(tc.blogKey)

if runtime.GOOS == "windows" {
tc.expect.LocalRoot = filepath.Clean(strings.ReplaceAll(tc.expect.LocalRoot, "/", "D:/"))
}
if !reflect.DeepEqual(*out, tc.expect) {
t.Errorf("something went wrong.\n out: %+v\nexpect: %+v", *out, tc.expect)
}
Expand Down Expand Up @@ -236,6 +247,9 @@ func TestLoadConfigration(t *testing.T) {
os.Chdir(tempdir)

if localConf != nil {
if runtime.GOOS == "windows" {
strings.ReplaceAll(*localConf, "local_root: /", "local_root: D:/")
}
err := ioutil.WriteFile(
filepath.Join(tempdir, "blogsync.yaml"), []byte(*localConf), 0755)
if err != nil {
Expand All @@ -245,6 +259,9 @@ func TestLoadConfigration(t *testing.T) {
}

if globalConf != nil {
if runtime.GOOS == "windows" {
strings.ReplaceAll(*globalConf, "local_root: /", "local_root: D:/")
}
globalConfFile := filepath.Join(tempdir, ".config", "blogsync", "config.yaml")
err := os.MkdirAll(filepath.Dir(globalConfFile), 0755)
if err != nil {
Expand Down Expand Up @@ -405,6 +422,9 @@ func TestLoadConfigration(t *testing.T) {
}
out := conf.Get(tc.blogKey)

if runtime.GOOS == "windows" {
tc.expect.LocalRoot = filepath.Clean(strings.ReplaceAll(tc.expect.LocalRoot, "/", "D:/"))
}
if !reflect.DeepEqual(*out, tc.expect) {
t.Errorf("something went wrong.\n out: %+v\nexpect: %+v", *out, tc.expect)
}
Expand Down

0 comments on commit 44a39dc

Please sign in to comment.