snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
126
server/pkg/apigw/pipeline/pipeline_test.go
Normal file
126
server/pkg/apigw/pipeline/pipeline_test.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/apigw/pipeline/chain"
|
||||
"github.com/cortezaproject/corteza/server/pkg/apigw/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
mockEmptyHandler = func(rw http.ResponseWriter, r *http.Request) (err error) { return }
|
||||
)
|
||||
|
||||
func NewPl() *Pl {
|
||||
return NewPipeline(zap.NewNop(), chain.NewDefault())
|
||||
}
|
||||
|
||||
func Test_pipelineAdd(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
p := NewPl()
|
||||
p.Add(&Worker{
|
||||
Handler: mockEmptyHandler,
|
||||
Weight: 0,
|
||||
Name: "mockWorker",
|
||||
})
|
||||
|
||||
req.Len(p.workers, 1)
|
||||
}
|
||||
|
||||
func Test_pipelineHandleMultiple(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
rr = httptest.NewRecorder()
|
||||
p = NewPl()
|
||||
|
||||
first = types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
rw.Write([]byte(`first`))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
second = types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
rw.Write([]byte(`second`))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
p.Add(&Worker{
|
||||
Handler: first.Handler(),
|
||||
Weight: 5,
|
||||
Name: "mockHandler",
|
||||
})
|
||||
|
||||
p.Add(&Worker{
|
||||
Handler: second.Handler(),
|
||||
Weight: 0,
|
||||
Name: "mockHandler",
|
||||
})
|
||||
|
||||
p.Handler().ServeHTTP(rr, &http.Request{})
|
||||
|
||||
req.Equal(`secondfirst`, rr.Body.String())
|
||||
}
|
||||
|
||||
func Test_pipelineExecErr(t *testing.T) {
|
||||
type (
|
||||
tf struct {
|
||||
name string
|
||||
mh types.MockHandler
|
||||
w *Worker
|
||||
wgt int
|
||||
exp string
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
tcc = []tf{
|
||||
{
|
||||
name: "matching simple",
|
||||
mh: types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
return fmt.Errorf("triggered")
|
||||
}},
|
||||
w: &Worker{},
|
||||
exp: `{"error":{"message":"triggered"}}` + "\n",
|
||||
},
|
||||
{
|
||||
name: "matching simple",
|
||||
mh: types.MockHandler{
|
||||
Handler_: func(rw http.ResponseWriter, r *http.Request) error {
|
||||
rw.Write([]byte(`foobar`))
|
||||
return nil
|
||||
}},
|
||||
w: &Worker{},
|
||||
exp: `foobar`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
for _, tc := range tcc {
|
||||
var (
|
||||
p = NewPl()
|
||||
rr = httptest.NewRecorder()
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
tc.w.Handler = tc.mh.Handler()
|
||||
|
||||
p.Add(tc.w)
|
||||
p.Handler().ServeHTTP(rr, &http.Request{})
|
||||
|
||||
req.Equal(tc.exp, rr.Body.String())
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user