test(web): improve
continuous-integration/drone the build failed
Details
continuous-integration/drone the build failed
Details
This commit is contained in:
parent
84fc14679b
commit
87ebc96f80
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue