This repository has been archived by the owner on Dec 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpull_test.go
133 lines (114 loc) · 3.27 KB
/
pull_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"path/filepath"
"strings"
"testing"
)
func TestPullLocaleFiles(t *testing.T) {
target := getBaseTarget()
localeFiles, err := target.LocaleFiles()
if err != nil {
t.Errorf("Should not fail with: %s", err.Error())
}
enPath, _ := filepath.Abs("./tests/en.yml")
dePath, _ := filepath.Abs("./tests/de.yml")
expectedFiles := []*LocaleFile{
{
Name: "english",
Code: "en",
ID: "en-locale-id",
Path: enPath,
},
{
Name: "german",
Code: "de",
ID: "de-locale-id",
Path: dePath,
},
}
if len(localeFiles) == len(expectedFiles) {
if err = compareLocaleFiles(localeFiles, expectedFiles); err != nil {
t.Errorf(err.Error())
}
} else {
t.Errorf("LocaleFiles should contain %v and not %v", expectedFiles, localeFiles)
}
}
func TestResolvedPath(t *testing.T) {
target := getBaseTarget()
target.File = "./<locale_code>/<tag>/<locale_name>.yml"
localeFile := &LocaleFile{
Name: "english",
Code: "en",
ID: "en-locale-id",
Tag: "abc",
Path: target.File,
}
newPath, err := target.ReplacePlaceholders(localeFile)
if err != nil {
t.Errorf(err.Error())
t.Fail()
}
if !strings.HasSuffix(newPath, "/en/abc/english.yml") {
t.Errorf("Expected the new path to eql '%s' and not %s", "/en/abc/english.yml", newPath)
}
}
func TestLocaleFiles__PlaceholdersWithLocaleID(t *testing.T) {
target := &Target{
File: "./tests/<locale_code>/<tag>.yml",
ProjectID: "project-id",
AccessToken: "access-token",
FileFormat: "yml",
Params: new(PullParams),
RemoteLocales: getBaseLocales(),
}
tags := "abc,abc2"
target.Params.Tags = &tags
target.Params.LocaleID = "en-locale-id"
files, err := target.LocaleFiles()
if err != nil {
t.Errorf(err.Error())
t.Fail()
}
if len(files) != 2 {
t.Errorf("Expected 2 files and and not %d", len(files))
}
if !strings.HasSuffix(files[0].Path, "/tests/en/abc.yml") {
t.Errorf("File path is '%s' and should end with '%s'", files[0].Path, "/tests/en/abc.yml")
}
if !strings.HasSuffix(files[1].Path, "/tests/en/abc2.yml") {
t.Errorf("File path is '%s' and should end with '%s'", files[1].Path, "/tests/en/abc2.yml")
}
}
func TestLocaleFiles__PlaceholdersWithoutLocaleID(t *testing.T) {
target := &Target{
File: "./tests/<locale_code>/<tag>.yml",
ProjectID: "project-id",
AccessToken: "access-token",
FileFormat: "yml",
Params: new(PullParams),
RemoteLocales: getBaseLocales(),
}
tags := "abc,abc2"
target.Params.Tags = &tags
files, err := target.LocaleFiles()
if err != nil {
t.Errorf(err.Error())
t.Fail()
}
if len(files) != 4 {
t.Errorf("Expected 4 files and and not %d", len(files))
}
if !strings.HasSuffix(files[0].Path, "/tests/en/abc.yml") {
t.Errorf("File path is '%s' and should end with '%s'", files[0].Path, "/tests/en/abc.yml")
}
if !strings.HasSuffix(files[1].Path, "/tests/en/abc2.yml") {
t.Errorf("File path is '%s' and should end with '%s'", files[1].Path, "/tests/en/abc2.yml")
}
if !strings.HasSuffix(files[2].Path, "/tests/de/abc.yml") {
t.Errorf("File path is '%s' and should end with '%s'", files[0].Path, "/tests/de/abc.yml")
}
if !strings.HasSuffix(files[3].Path, "/tests/de/abc2.yml") {
t.Errorf("File path is '%s' and should end with '%s'", files[1].Path, "/tests/de/abc2.yml")
}
}