Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Remote sources should skip Native Projects #197

Merged
merged 1 commit into from
Jul 26, 2023
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
6 changes: 2 additions & 4 deletions internal/txlib/add_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ func AddRemoteCommand(
}
i18nFormat, exists := i18nFormats[i18nFormatRelationship.DataSingular.Id]
if !exists {
return fmt.Errorf(
"could not find file Format: %s",
resource.Relationships["i18n_format"].DataSingular.Id,
)
fmt.Printf("Resource %s skipped: Invalid file Format %s\n", resource.Id, i18nFormatRelationship.DataSingular.Id)
continue
}

// Construct file-filter
Expand Down
78 changes: 78 additions & 0 deletions internal/txlib/add_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package txlib

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"reflect"
"strings"
"testing"

"github.com/transifex/cli/internal/txlib/config"
Expand Down Expand Up @@ -82,3 +84,79 @@ func TestAddRemote(t *testing.T) {
t.Errorf("Got request '%+v', expected '%+v'", actual, expected)
}
}

func TestAddRemoteInvalidFileFormat(t *testing.T) {
curDir, _ := os.Getwd()
tempDir, _ := os.MkdirTemp("", "")
defer os.RemoveAll(tempDir)
_ = os.Chdir(tempDir)
defer os.Chdir(curDir)

resourcesUrl := fmt.Sprintf(
"/resources?%s=%s",
url.QueryEscape("filter[project]"),
url.QueryEscape(projectId),
)
i18nFormatsUrl := fmt.Sprintf(
"/i18n_formats?%s=%s",
url.QueryEscape("filter[organization]"),
url.QueryEscape("o:orgslug"),
)

// Capture stdout
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

mockData := jsonapi.MockData{
projectUrl: getProjectEndpoint(),
resourcesUrl: jsonapi.GetMockTextResponse(
`{"data": [{
"type": "resources",
"id": "o:orgslug:p:projslug:r:resslug",
"attributes": {"slug": "resslug"},
"relationships": {
"i18n_format": {"data": {"type": "i18n_formats", "id": "FILELESS"}}
}
}]}`,
),
i18nFormatsUrl: jsonapi.GetMockTextResponse(
`{"data": [{
"type": "i18n_formats",
"id": "PO",
"attributes": {"file_extensions": [".po"]}
}]}`,
),
}

api := jsonapi.GetTestConnection(mockData)
cfg := &config.Config{Local: &config.LocalConfig{}}

err := AddRemoteCommand(
cfg,
&api,
"https://app.transifex.com/orgslug/projslug/whatever/whatever/",
// Lets make the file filter a bit weird
"locale/<project_slug><project_slug>.<resource_slug>/<lang>.<ext>",
50,
)
if err != nil {
t.Errorf("%s", err)
}

// Restore stdout
w.Close()
os.Stdout = oldStdout
out, _ := ioutil.ReadAll(r)
r.Close()

testSimpleGet(t, mockData, projectUrl)
testSimpleGet(t, mockData, resourcesUrl)
testSimpleGet(t, mockData, i18nFormatsUrl)

// Check if the expected error message was printed
expectedErrorMessage := "Resource o:orgslug:p:projslug:r:resslug skipped: Invalid file Format FILELESS"
if !strings.Contains(string(out), expectedErrorMessage) {
t.Errorf("Expected error message '%s' not found in printed output", expectedErrorMessage)
}
}
Loading