This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from mercari/server_test
test: Add test cases for server.go
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package gaurun | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRegisterHandlers(t *testing.T) { | ||
mux := http.NewServeMux() | ||
|
||
RegisterHandlers(mux) | ||
|
||
entrypoints := []string{ | ||
"/push", | ||
"/stat/app", | ||
"/config/pushers", | ||
"/stat/go", | ||
} | ||
|
||
for _, e := range entrypoints { | ||
_, pattern := mux.Handler(&http.Request{ | ||
Method: "GET", Host: "localhost", URL: &url.URL{Path: e}, | ||
}) | ||
assert.Equal(t, e, pattern) | ||
} | ||
} | ||
|
||
func TestGetListener(t *testing.T) { | ||
validConfigs := []ConfToml{ | ||
{Core: SectionCore{Port: "8080"}}, | ||
{Core: SectionCore{Port: "unix:/tmp/gaurun.sock"}}, | ||
} | ||
invalidConfigs := []ConfToml{ | ||
// port is empty | ||
{}, | ||
// port is not listenable | ||
{Core: SectionCore{Port: "100000"}}, | ||
// port specified neither TCP port nor UNIX socket | ||
{Core: SectionCore{Port: "invalid:/invalid"}}, | ||
} | ||
|
||
for _, c := range validConfigs { | ||
_, err := getListener(&c) | ||
assert.Nil(t, err) | ||
} | ||
|
||
for _, c := range invalidConfigs { | ||
_, err := getListener(&c) | ||
assert.NotNil(t, err) | ||
} | ||
} |