-
Notifications
You must be signed in to change notification settings - Fork 38
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
fix: logger methods , structural changes , removed pubsub , changed config structure and some minor tweaks, unit test cases #400
base: beckn-onix-v1.0-develop
Are you sure you want to change the base?
Conversation
…onfig structure and some minor tweaks
cmd/clientSideHandler/config.yaml
Outdated
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.
As I commented earlier move this to configs folder as per the shared folder structure
|
||
import ( | ||
shared "beckn-onix/shared" | ||
"context" |
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.
please read up on grouping imports,
We should divide the imports into following groups :
- Standard library packages
- BecknOnix packages
- ThirdParty Packages
4 Renamed Packages
5 blank imports
Read up on this https://blog.devgenius.io/sort-go-imports-acb76224dfa7
And make the required changes everywhere else as well.
cmd/clientSideHandler/main.go
Outdated
|
||
type Config struct { | ||
AppName string `yaml:"app_name"` | ||
ServerPort int `yaml:"port"` |
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 should be just port
cmd/clientSideHandler/main.go
Outdated
|
||
|
||
type Config struct { | ||
AppName string `yaml:"app_name"` |
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.
when using yaml naming convention is governed by surrounding code. Since we are using golang lets stick to camelcase
cmd/clientSideHandler/main.go
Outdated
) | ||
|
||
|
||
type Config struct { |
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.
why is this exported ?
) | ||
|
||
// TestInitConfig checks if the InitConfig function correctly reads a YAML file | ||
func TestInitConfig(t *testing.T) { |
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.
Please split all test into 2 separate tests, 1 for success and one for error case, also use table driven tests,
https://golang.cafe/blog/golang-table-test-example
t.Fatalf("InitConfig failed: %v", err) | ||
} | ||
|
||
// Validate results |
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 not the right way for testing this, as we will have to update this every time we add a new field to config, instead of doing this create and expected config and do a diff agains it, use this package https://pkg.go.dev/github.com/google/go-cmp/cmp
if err != nil { | ||
http.Error(w, "Error reading body", http.StatusInternalServerError) | ||
return | ||
} |
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 not needed
} | ||
|
||
if string(body) != `{"message": "Hello"}` { | ||
t.Errorf("Expected body: %s, got: %s", `{"message": "Hello"}`, string(body)) |
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.
why are we testing the request. ?
// Validate response body | ||
expectedResponse := "Message received successfully" | ||
if rec.Body.String() != expectedResponse { | ||
t.Errorf("Expected response body: %q, got: %q", expectedResponse, rec.Body.String()) |
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.
As I have commented on the main file making the handler method independent will make all this much simpler.
fix: logger methods , structural changes , removed pubsub , changed config structure and some minor tweaks