diff --git a/web/main_test.go b/web/main_test.go index efb3895..e1871c0 100644 --- a/web/main_test.go +++ b/web/main_test.go @@ -1 +1,31 @@ package web + +import ( + "testing" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +func TestRun(t *testing.T) { + assert := assert.New(t) + + ModuleRegister(func(_ *gin.Engine, _ *Service) { + }) + + s := &Service{AccessLog: true, Listen: ":80"} + // HTTP - failed + err := s.Run() + assert.Error(err) + + s.ACME.Enable = true + // acme with listen port - panic + assert.Panics(func() { + s.Run() + }) + + s.Listen = "" + // httpS - failed + err = s.Run() + assert.Error(err) +} diff --git a/web/request_test.go b/web/request_test.go new file mode 100644 index 0000000..733f00b --- /dev/null +++ b/web/request_test.go @@ -0,0 +1,26 @@ +package web + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestJSONRequest(t *testing.T) { + assert := assert.New(t) + + data := struct { + IP string `json:"ip"` + }{} + err := JSONRequest("http://ip.jsontest.com/", &data) + assert.NoError(err) + assert.NotEqual("", data.IP) + + wrongData := "" + err = JSONRequest("http://ip.jsontest.com/", &wrongData) + assert.Error(err) + + wrongData = "" + err = JSONRequest("http://no.example.org/", &wrongData) + assert.Error(err) +}