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

test: Add Go tests #440

Merged
merged 15 commits into from
Oct 23, 2023
Merged

test: Add Go tests #440

merged 15 commits into from
Oct 23, 2023

Conversation

hahmed-dev
Copy link
Contributor

@hahmed-dev hahmed-dev commented Oct 20, 2023

Add basic tests for Go Lang.

Related Issue: https://phrase.atlassian.net/browse/TSI-2123

@hahmed-dev hahmed-dev changed the title TSI-2123 Add Basic Go Lang Test Cases test: Add Go tests Oct 20, 2023
@hahmed-dev hahmed-dev marked this pull request as ready for review October 20, 2023 11:05
jablan
jablan previously requested changes Oct 20, 2023
Copy link
Collaborator

@jablan jablan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, some questions added, but nothing super important.

.gitignore Outdated
@@ -56,6 +54,19 @@ clients/php/test/Api/*
!clients/php/test/Api/LocalesApiTest.php
!clients/php/test/Api/UploadsApiTest.php

clients/go/*.go
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've discussed this here #427 (comment) and decided not to go this individual exclusion route. so, feel free to leave this file as is, and only git add -f files that need to be added.

apiClient := phrase.NewAPIClient(configuration)


t.Run("Test LocalesApiService AccountLocales", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd delete these unused tests.

t.Run("Test LocalesApiService LocalesList", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Send the mock response
response := `[{"foo": "bar"}]`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also return a proper format and actually assert that returned locales are deserialized properly?

apiClient := phrase.NewAPIClient(configuration)

t.Run("Test UploadsApiService UploadCreate", func(t *testing.T) {
localVarOptionals := phrase.UploadCreateOpts{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how easy would it be to pass an actual file to this call and then assert that the body contains it?

Copy link
Contributor Author

@hahmed-dev hahmed-dev Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked into it, tried to access request via http.response object

httpRes.Request.Body 

But it returned {}

Also tried to explore possibility to read the request Body inside the mock server but I will have to look further how to handle the returned Body object of type io.ReadCloser which by default is unreadable. If its important, I can further investigate if its possible.

Copy link
Collaborator

@theSoenke theSoenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@hahmed-dev hahmed-dev dismissed jablan’s stale review October 23, 2023 08:36

Approved by Sonke and Mladen is on vacation.

@hahmed-dev hahmed-dev merged commit 12b06d6 into master Oct 23, 2023
10 checks passed
@hahmed-dev hahmed-dev deleted the tsi-2123-go-testcases branch October 23, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants