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

Modify the test module, add the file upload test, and add the image edit api #63

Merged
merged 6 commits into from
Feb 11, 2023

Conversation

Rascal0814
Copy link
Contributor

  • Because the test files are all written in one file, I think it is unreasonable to make changes
  • File upload test
  • Add image edit api and corresponding test file
  • An adjustment has been made to OpenAITestServer. The test needs to register the handler with the server

@sashabaranov
Copy link
Owner

Thank you for the PR! 🙌🏻

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

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

This is an excellent PR! Just a couple of minor comments 🚀

image_test.go Outdated
return
}

mask, err := os.Open("./static/image_edit_mask.png")
Copy link
Owner

Choose a reason for hiding this comment

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

It's a bit of overkill bringing static images into the repo to test with the mock server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌

@@ -0,0 +1,43 @@
package api
Copy link
Owner

Choose a reason for hiding this comment

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

May I suggest we place it into /test or /testing or /internal/test[ing]? The /internal/api might look like it's not test-related.

See also: https://github.com/golang-standards/project-layout

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we can even place this file on the root level and make the whole test server stuff non-exportable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although internal cannot be exported, in order to simplify the project structure, it is better to put it in the root directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another problem is that the package of the test file is different from that of the normal file. Therefore, if the method is set to not exportable, it cannot be accessed

type Handler func(w http.ResponseWriter, r *http.Request)

// serverMap.
var serverMap = make(map[string]Handler)
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure that global map is a good idea here, maybe we can do something along the lines of:

type TestServer struct {
	handlers map[string]Handler
}

func NewTestServer() *TestServer { ... }
func (ts *TestServer) RegisterHandler(path string, handler Handler) { ... }

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the map in RegisterHandler be determined whether it exists or directly overwritten?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think global map is feasible here, and there is no need to consider concurrency. Maybe I think it is simple, don't you think?

Copy link
Owner

Choose a reason for hiding this comment

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

We also have GetTestToken here, I think it makes sense to keep test-server-related logic encapsulated in a single tidy struct, in that way, it would be obvious how to extend the test server in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I'll make it simple

@sashabaranov
Copy link
Owner

Thank you for all the changes!

@sashabaranov sashabaranov merged commit 5191ea6 into sashabaranov:master Feb 11, 2023
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.

2 participants