mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 21:22:15 +01:00
adding missingt test in context package
This commit is contained in:
@@ -26,12 +26,12 @@ type Context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Context.
|
// New creates a new Context.
|
||||||
func New(c echo.Context, logger xlog.Logger, config conf.Config, processess ...pm2.Process) Context {
|
func New(c echo.Context, logger xlog.Logger, config conf.Config, processes ...pm2.Process) Context {
|
||||||
return Context{
|
return Context{
|
||||||
c,
|
c,
|
||||||
logger,
|
logger,
|
||||||
config,
|
config,
|
||||||
processess,
|
processes,
|
||||||
resource.Resource{},
|
resource.Resource{},
|
||||||
time.Now(),
|
time.Now(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/conf"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/conf"
|
||||||
|
"github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
|
||||||
"github.com/thecodingmachine/gotenberg/test"
|
"github.com/thecodingmachine/gotenberg/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,6 +27,27 @@ func TestMustCastFromEchoContext(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessesHealthcheck(t *testing.T) {
|
||||||
|
// process is viable.
|
||||||
|
ctx := New(
|
||||||
|
test.DummyEchoContext(),
|
||||||
|
test.DebugLogger(),
|
||||||
|
conf.DefaultConfig(),
|
||||||
|
pm2.NewDummyProcess(true),
|
||||||
|
)
|
||||||
|
err := ctx.ProcessesHealthcheck()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
// process is not viable.
|
||||||
|
ctx = New(
|
||||||
|
test.DummyEchoContext(),
|
||||||
|
test.DebugLogger(),
|
||||||
|
conf.DefaultConfig(),
|
||||||
|
pm2.NewDummyProcess(false),
|
||||||
|
)
|
||||||
|
err = ctx.ProcessesHealthcheck()
|
||||||
|
test.AssertError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestLogRequestResult(t *testing.T) {
|
func TestLogRequestResult(t *testing.T) {
|
||||||
ctx := New(
|
ctx := New(
|
||||||
test.DummyEchoContext(),
|
test.DummyEchoContext(),
|
||||||
|
|||||||
46
internal/pkg/pm2/dummy.go
Normal file
46
internal/pkg/pm2/dummy.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package pm2
|
||||||
|
|
||||||
|
type dummyProcess struct {
|
||||||
|
isViable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDummyProcess returns a dummy
|
||||||
|
// process.
|
||||||
|
func NewDummyProcess(isViable bool) Process {
|
||||||
|
return dummyProcess{
|
||||||
|
isViable: isViable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) Fullname() string {
|
||||||
|
return "dummy process"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) Start() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) IsViable() bool {
|
||||||
|
return p.isViable
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) Stop() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) args() []string {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) binary() string {
|
||||||
|
return "dummy"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p dummyProcess) warmup() {
|
||||||
|
// let's do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile-time checks to ensure type implements desired interfaces.
|
||||||
|
var (
|
||||||
|
_ = Process(new(dummyProcess))
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user