Skip to content

Commit 5acb442

Browse files
authored
Merge pull request #197 from transifex/TX-14394_add_remote_skip_native
Add Remote sources should skip Native Projects
2 parents 05c3163 + f755451 commit 5acb442

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

internal/txlib/add_remote.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ func AddRemoteCommand(
7272
}
7373
i18nFormat, exists := i18nFormats[i18nFormatRelationship.DataSingular.Id]
7474
if !exists {
75-
return fmt.Errorf(
76-
"could not find file Format: %s",
77-
resource.Relationships["i18n_format"].DataSingular.Id,
78-
)
75+
fmt.Printf("Resource %s skipped: Invalid file Format %s\n", resource.Id, i18nFormatRelationship.DataSingular.Id)
76+
continue
7977
}
8078

8179
// Construct file-filter

internal/txlib/add_remote_test.go

+78
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package txlib
22

33
import (
44
"fmt"
5+
"io/ioutil"
56
"net/url"
67
"os"
78
"reflect"
9+
"strings"
810
"testing"
911

1012
"github.com/transifex/cli/internal/txlib/config"
@@ -82,3 +84,79 @@ func TestAddRemote(t *testing.T) {
8284
t.Errorf("Got request '%+v', expected '%+v'", actual, expected)
8385
}
8486
}
87+
88+
func TestAddRemoteInvalidFileFormat(t *testing.T) {
89+
curDir, _ := os.Getwd()
90+
tempDir, _ := os.MkdirTemp("", "")
91+
defer os.RemoveAll(tempDir)
92+
_ = os.Chdir(tempDir)
93+
defer os.Chdir(curDir)
94+
95+
resourcesUrl := fmt.Sprintf(
96+
"/resources?%s=%s",
97+
url.QueryEscape("filter[project]"),
98+
url.QueryEscape(projectId),
99+
)
100+
i18nFormatsUrl := fmt.Sprintf(
101+
"/i18n_formats?%s=%s",
102+
url.QueryEscape("filter[organization]"),
103+
url.QueryEscape("o:orgslug"),
104+
)
105+
106+
// Capture stdout
107+
oldStdout := os.Stdout
108+
r, w, _ := os.Pipe()
109+
os.Stdout = w
110+
111+
mockData := jsonapi.MockData{
112+
projectUrl: getProjectEndpoint(),
113+
resourcesUrl: jsonapi.GetMockTextResponse(
114+
`{"data": [{
115+
"type": "resources",
116+
"id": "o:orgslug:p:projslug:r:resslug",
117+
"attributes": {"slug": "resslug"},
118+
"relationships": {
119+
"i18n_format": {"data": {"type": "i18n_formats", "id": "FILELESS"}}
120+
}
121+
}]}`,
122+
),
123+
i18nFormatsUrl: jsonapi.GetMockTextResponse(
124+
`{"data": [{
125+
"type": "i18n_formats",
126+
"id": "PO",
127+
"attributes": {"file_extensions": [".po"]}
128+
}]}`,
129+
),
130+
}
131+
132+
api := jsonapi.GetTestConnection(mockData)
133+
cfg := &config.Config{Local: &config.LocalConfig{}}
134+
135+
err := AddRemoteCommand(
136+
cfg,
137+
&api,
138+
"https://app.transifex.com/orgslug/projslug/whatever/whatever/",
139+
// Lets make the file filter a bit weird
140+
"locale/<project_slug><project_slug>.<resource_slug>/<lang>.<ext>",
141+
50,
142+
)
143+
if err != nil {
144+
t.Errorf("%s", err)
145+
}
146+
147+
// Restore stdout
148+
w.Close()
149+
os.Stdout = oldStdout
150+
out, _ := ioutil.ReadAll(r)
151+
r.Close()
152+
153+
testSimpleGet(t, mockData, projectUrl)
154+
testSimpleGet(t, mockData, resourcesUrl)
155+
testSimpleGet(t, mockData, i18nFormatsUrl)
156+
157+
// Check if the expected error message was printed
158+
expectedErrorMessage := "Resource o:orgslug:p:projslug:r:resslug skipped: Invalid file Format FILELESS"
159+
if !strings.Contains(string(out), expectedErrorMessage) {
160+
t.Errorf("Expected error message '%s' not found in printed output", expectedErrorMessage)
161+
}
162+
}

0 commit comments

Comments
 (0)