Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #83 from mercari/server_test
Browse files Browse the repository at this point in the history
test: Add test cases for server.go
  • Loading branch information
cubicdaiya authored Sep 29, 2017
2 parents 16a53e0 + e6b8301 commit a31b57e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions gaurun/server_test.go
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)
}
}

0 comments on commit a31b57e

Please sign in to comment.