golang-lib/web/main_test.go

38 lines
591 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-09-29 14:30:17 +02:00
"go.uber.org/zap"
2021-06-23 15:00:03 +02:00
)
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)
2021-06-23 20:48:08 +02:00
s := &Service{AccessLog: true, Listen: "8.8.8.8:80"}
2021-07-19 18:35:44 +02:00
s.ModuleRegister(func(_ *gin.Engine, _ *Service) {})
2021-06-23 15:00:03 +02:00
// HTTP - failed
2021-09-29 14:30:17 +02:00
err := s.Run(zap.L())
2021-06-23 15:00:03 +02:00
assert.Error(err)
s.ACME.Enable = true
// acme with listen port - panic
assert.Panics(func() {
2021-09-29 14:30:17 +02:00
s.Run(zap.L())
2021-06-23 15:00:03 +02:00
})
2021-06-23 21:23:46 +02:00
if TestRunTLS == "false" {
return
}
2021-06-23 15:00:03 +02:00
s.Listen = ""
// httpS - failed
2021-09-29 14:30:17 +02:00
err = s.Run(zap.L())
2021-06-23 15:00:03 +02:00
assert.Error(err)
}