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

Use non-empty structs in test server handlers #487

Open
sashabaranov opened this issue Sep 5, 2023 · 0 comments
Open

Use non-empty structs in test server handlers #487

sashabaranov opened this issue Sep 5, 2023 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@sashabaranov
Copy link
Owner

sashabaranov commented Sep 5, 2023

Currently, in many test cases, we return empty structs from the test server. For example:

server.RegisterHandler("/v1/engines/text-davinci-003", func(w http.ResponseWriter, r *http.Request) {
	resBytes, _ := json.Marshal(Engine{}) // <------------- Here we return empty Engine struct
	fmt.Fprintln(w, string(resBytes))
})

It is possible for such tests not to cover a case where client does not return a proper response, see for example this discussion: #485 (comment)

It would be good to make these structs non-empty, and the best solution would probably be to randomize them (keeping randomization logic in the internal/test directory). So in the end we'll get something like:

server.RegisterHandler("/v1/engines/text-davinci-003", func(w http.ResponseWriter, r *http.Request) {
	resBytes, _ := json.Marshal(Engine{ID: test.randomString(), Object: test.randomString()})
	fmt.Fprintln(w, string(resBytes))
})
@sashabaranov sashabaranov added enhancement New feature or request good first issue Good for newcomers labels Sep 5, 2023
ealvar3z added a commit to ealvar3z/go-openai that referenced this issue Sep 12, 2023
- Add randomized fields to Engine structs in tests
- Implement cryptographically secure random utility functions
- Address golangci-lint warnings
ealvar3z added a commit to ealvar3z/go-openai that referenced this issue Sep 14, 2023
- Avoid big package
- Use strings.Builder for efficient string concatenation
- Set default string length to 10
- Handle errors from rand.Read()

Resolves: sashabaranov#487
ealvar3z added a commit to ealvar3z/go-openai that referenced this issue Sep 14, 2023
- Memory efficient solution for RandomInt func
- Improve error handling by logging them vice returning the type
- Use RandomInt() instead

Resolves: sashabaranov#487
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant