-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
Rascal0814
commented
Feb 9, 2023
- 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
Thank you for the PR! 🙌🏻 |
There was a problem hiding this 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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
internal/api/server.go
Outdated
@@ -0,0 +1,43 @@ | |||
package api |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
internal/api/server.go
Outdated
type Handler func(w http.ResponseWriter, r *http.Request) | ||
|
||
// serverMap. | ||
var serverMap = make(map[string]Handler) |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Thank you for all the changes! |