golang-lib/web/main_test.go

39 lines
552 B
Go
Raw Normal View History

2021-06-01 10:51:35 +02:00
package web
2021-06-23 15:00:03 +02:00
import (
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
2021-06-23 21:23:46 +02:00
var (
TestRunTLS = ""
)
2021-06-23 15:00:03 +02:00
func TestRun(t *testing.T) {
assert := assert.New(t)
ModuleRegister(func(_ *gin.Engine, _ *Service) {
})
2021-06-23 20:48:08 +02:00
s := &Service{AccessLog: true, Listen: "8.8.8.8:80"}
2021-06-23 15:00:03 +02:00
// HTTP - failed
err := s.Run()
assert.Error(err)
s.ACME.Enable = true
// acme with listen port - panic
assert.Panics(func() {
s.Run()
})
2021-06-23 21:23:46 +02:00
if TestRunTLS == "false" {
return
}
2021-06-23 15:00:03 +02:00
s.Listen = ""
// httpS - failed
err = s.Run()
assert.Error(err)
}