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

fix: logger methods , structural changes , removed pubsub , changed config structure and some minor tweaks, unit test cases #400

Open
wants to merge 9 commits into
base: beckn-onix-v1.0-develop
Choose a base branch
from

Conversation

MayurWitsLab
Copy link

fix: logger methods , structural changes , removed pubsub , changed config structure and some minor tweaks

@MayurWitsLab MayurWitsLab changed the title fix: logger methods , structural changes , removed pubsub , changed config structure and some minor tweaks fix: logger methods , structural changes , removed pubsub , changed config structure and some minor tweaks, unit test cases Feb 19, 2025
Copy link
Collaborator

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"
Copy link
Collaborator

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 :

  1. Standard library packages
  2. BecknOnix packages
  3. 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.


type Config struct {
AppName string `yaml:"app_name"`
ServerPort int `yaml:"port"`
Copy link
Collaborator

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



type Config struct {
AppName string `yaml:"app_name"`
Copy link
Collaborator

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

)


type Config struct {
Copy link
Collaborator

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) {
Copy link
Collaborator

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
Copy link
Collaborator

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
}
Copy link
Collaborator

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))
Copy link
Collaborator

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())
Copy link
Collaborator

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.

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