Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
150 changes: 43 additions & 107 deletions generator/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
})
}
}