diff --git a/engine/factory_test.go b/engine/factory_test.go index 3e20a61..d1a411b 100644 --- a/engine/factory_test.go +++ b/engine/factory_test.go @@ -125,7 +125,7 @@ func TestFactory_New_reloadTemplate(t *testing.T) { time.Sleep(200 * time.Millisecond) - // Non-existant file param + // Non-existent file param req, _ := http.NewRequest("PUT", "/template/a", nil) resp := httptest.NewRecorder() e.ServeHTTP(resp, req) diff --git a/generator/scan_test.go b/generator/scan_test.go index 8aa6a49..0b97c2c 100644 --- a/generator/scan_test.go +++ b/generator/scan_test.go @@ -2,121 +2,57 @@ package generator import ( "fmt" - "log" "os" "testing" ) func TestTmplScanner(t *testing.T) { - pwd := os.Getenv("PWD") - sourceFolder := fmt.Sprintf("%s/test/sources", pwd) - - iso := "en-US" - paths := []string{ - fmt.Sprintf("%s/global", sourceFolder), - fmt.Sprintf("%s/%s", sourceFolder, iso), - } - scanner := NewScanner(paths) - tmpls := scanner.Scan() - log.Println(tmpls) - if len(tmpls) != 2 { - t.Errorf("[%s] unexpected scan result. have %d nodes, want %d", iso, len(tmpls), 2) - return - } - if tmpls[0].Path != paths[0] { - t.Errorf("[%s - 0] unexpected path. have %s, want %s", iso, tmpls[0].Path, paths[0]) - return - } - if len(tmpls[0].Content) != 4 { - t.Errorf("[%s - 0] unexpected content size. have %d, want 4", iso, len(tmpls[0].Content)) - return - } - if tmpls[1].Path != paths[1] { - t.Errorf("[%s - 1] unexpected path. have %s, want %s", iso, tmpls[1].Path, paths[1]) - return - } - if len(tmpls[1].Content) != 1 { - t.Errorf("[%s - 1] unexpected content size. have %d, want 1", iso, len(tmpls[1].Content)) - return + tt := []struct { + iso string + nodes int + }{ + {"en-US", 2}, + {"en-UK", 2}, + {"es-ES", 2}, + {"unknown", 1}, } - iso = "en-UK" - paths = []string{ - fmt.Sprintf("%s/global", sourceFolder), - fmt.Sprintf("%s/%s", sourceFolder, iso), - } - scanner = NewScanner(paths) - - tmpls = scanner.Scan() - if len(tmpls) != 2 { - t.Errorf("[%s] unexpected scan result. have %d nodes, want %d", iso, len(tmpls), 2) - return - } - if tmpls[0].Path != paths[0] { - t.Errorf("[%s - 0] unexpected path. have %s, want %s", iso, tmpls[0].Path, paths[0]) - return - } - if len(tmpls[0].Content) != 4 { - t.Errorf("[%s - 0] unexpected content size. have %d, want 4", iso, len(tmpls[0].Content)) - return - } - if tmpls[1].Path != paths[1] { - t.Errorf("[%s - 1] unexpected path. have %s, want %s", iso, tmpls[1].Path, paths[1]) - return - } - if len(tmpls[1].Content) != 1 { - t.Errorf("[%s - 1] unexpected content size. have %d, want 1", iso, len(tmpls[1].Content)) - return - } - - iso = "es-ES" - paths = []string{ - fmt.Sprintf("%s/global", sourceFolder), - fmt.Sprintf("%s/%s", sourceFolder, iso), - } - scanner = NewScanner(paths) - - tmpls = scanner.Scan() - if len(tmpls) != 2 { - t.Errorf("[%s] unexpected scan result. have %d nodes, want %d", iso, len(tmpls), 2) - return - } - if tmpls[0].Path != paths[0] { - t.Errorf("[%s - 0] unexpected path. have %s, want %s", iso, tmpls[0].Path, paths[0]) - return - } - if len(tmpls[0].Content) != 4 { - t.Errorf("[%s - 0] unexpected content size. have %d, want 4", iso, len(tmpls[0].Content)) - return - } - if tmpls[1].Path != paths[1] { - t.Errorf("[%s - 1] unexpected path. have %s, want %s", iso, tmpls[1].Path, paths[1]) - return - } - if len(tmpls[1].Content) != 1 { - t.Errorf("[%s - 1] unexpected content size. have %d, want 1", iso, len(tmpls[1].Content)) - return - } - - iso = "unknown" - paths = []string{ - fmt.Sprintf("%s/global", sourceFolder), - fmt.Sprintf("%s/%s", sourceFolder, iso), - } - scanner = NewScanner(paths) + pwd := os.Getenv("PWD") + sourceFolder := fmt.Sprintf("%s/test/sources", pwd) - tmpls = scanner.Scan() - if len(tmpls) != 1 { - t.Errorf("[%s] unexpected scan result. have %d nodes, want %d", iso, len(tmpls), 2) - return - } - if tmpls[0].Path != paths[0] { - t.Errorf("[%s - 0] unexpected path. have %s, want %s", iso, tmpls[0].Path, paths[0]) - return - } - if len(tmpls[0].Content) != 4 { - t.Errorf("[%s - 0] unexpected content size. have %d, want 4", iso, len(tmpls[0].Content)) - return + for _, tc := range tt { + t.Run(tc.iso, func(t *testing.T) { + paths := []string{ + fmt.Sprintf("%s/global", sourceFolder), + fmt.Sprintf("%s/%s", sourceFolder, tc.iso), + } + scanner := NewScanner(paths) + + tmpls := scanner.Scan() + if len(tmpls) != tc.nodes { + t.Errorf("[%s] unexpected scan result. have %d nodes, want %d", tc.iso, len(tmpls), tc.nodes) + return + } + + if tmpls[0].Path != paths[0] { + t.Errorf("[%s - 0] unexpected path. have %s, want %s", tc.iso, tmpls[0].Path, paths[0]) + return + } + if len(tmpls[0].Content) != 4 { + t.Errorf("[%s - 0] unexpected content size. have %d, want 4", tc.iso, len(tmpls[0].Content)) + return + } + if tc.nodes > 1 { + if tmpls[1].Path != paths[1] { + t.Errorf("[%s - 1] unexpected path. have %s, want %s", tc.iso, tmpls[1].Path, paths[1]) + return + } + if len(tmpls[1].Content) != 1 { + t.Errorf("[%s - 1] unexpected content size. have %d, want 1", tc.iso, len(tmpls[1].Content)) + return + } + } + }) } }