test(web): improve
continuous-integration/drone the build failed Details

This commit is contained in:
Geno 2021-06-23 15:00:03 +02:00
parent 84fc14679b
commit 87ebc96f80
2 changed files with 56 additions and 0 deletions

View File

@ -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)
}

26
web/request_test.go Normal file
View File

@ -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)
}