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

patch: modified the Route.Run() to use APP_PORT #58

Merged
merged 8 commits into from
Feb 28, 2023
14 changes: 12 additions & 2 deletions route/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ func (r *Gin) Run(host ...string) error {
return errors.New("host can't be empty")
}

host = append(host, defaultHost)
defaultPort := facades.Config.GetString("route.port")
if defaultPort == "" {
return errors.New("port can't be empty")
}
completeHost := defaultHost + ":" + defaultPort
host = append(host, completeHost)
Copy link
Contributor

Choose a reason for hiding this comment

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

Great Bro, can you also change the RunTLS method like this? Then we also need to change the config/route.go file in goravel/goravel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I have pushed the changes, I am just try to fix failing test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @hwbrzzl can you help me with testcases, I am not able to resolve them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hwbrzzl There is some issue with testcases, I am trying to debug it, will push it by Wednesday.

}

outputRoutes(r.instance.Routes())
Expand All @@ -56,7 +61,12 @@ func (r *Gin) RunTLS(host ...string) error {
return errors.New("host can't be empty")
}

host = append(host, defaultHost)
defaultPort := facades.Config.GetString("route.tls.port")
if defaultPort == "" {
return errors.New("port can't be empty")
}
completeHost := defaultHost + ":" + defaultPort
host = append(host, completeHost)
}

certFile := facades.Config.GetString("route.tls.ssl.cert")
Expand Down
4 changes: 4 additions & 0 deletions route/gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestRun(t *testing.T) {
name: "error when default host is empty",
setup: func(host string) error {
mockConfig.On("GetString", "route.host").Return(host).Once()
mockConfig.On("GetString", "route.port").Return("test_ca.port").Once()
Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't need to add this, because we are testing host can't be empty.
We need to add a test case: port can't be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I have added it.


go func() {
assert.EqualError(t, route.Run(), "host can't be empty")
Expand All @@ -53,6 +54,7 @@ func TestRun(t *testing.T) {
setup: func(host string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
setup: func(host string) error {
setup: func(host, port string) error {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

mockConfig.On("GetBool", "app.debug").Return(true).Once()
mockConfig.On("GetString", "route.host").Return(host).Once()
mockConfig.On("GetString", "route.port").Return("test_ca.port").Once()

go func() {
assert.Nil(t, route.Run())
Expand Down Expand Up @@ -116,6 +118,7 @@ func TestRunTLS(t *testing.T) {
name: "error when default host is empty",
setup: func(host string) error {
mockConfig.On("GetString", "route.tls.host").Return(host).Once()
mockConfig.On("GetString", "route.tls.port").Return("test_ca.port").Once()

go func() {
assert.EqualError(t, route.RunTLS(), "host can't be empty")
Expand All @@ -130,6 +133,7 @@ func TestRunTLS(t *testing.T) {
setup: func(host string) error {
mockConfig.On("GetBool", "app.debug").Return(true).Once()
mockConfig.On("GetString", "route.tls.host").Return(host).Once()
mockConfig.On("GetString", "route.tls.port").Return("test_ca.port").Once()
mockConfig.On("GetString", "route.tls.ssl.cert").Return("test_ca.crt").Once()
mockConfig.On("GetString", "route.tls.ssl.key").Return("test_ca.key").Once()

Expand Down