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:
66
server/pkg/api/response_test.go
Normal file
66
server/pkg/api/response_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"io/ioutil"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
func TestTests(t *testing.T) {
|
||||
testResponse := func(output interface{}) string {
|
||||
w := httptest.NewRecorder()
|
||||
r := &http.Request{Header: http.Header{}}
|
||||
r.Header.Add("accept", "application/json")
|
||||
Send(w, r, output)
|
||||
body, _ := ioutil.ReadAll(w.Result().Body)
|
||||
return string(body)
|
||||
}
|
||||
|
||||
var cc = []struct {
|
||||
name string
|
||||
inp interface{}
|
||||
out string
|
||||
}{
|
||||
{"nil", nil, `{"response":false}`},
|
||||
{"bool true", true, `{"response":true}`},
|
||||
{"bool false", false, `{"response":false}`},
|
||||
{"string empty", "", `{"response":false}`},
|
||||
{"string", "string", `{"response":"string"}`},
|
||||
{"int zero", 0, `{"response":0}`},
|
||||
{"int non-zero", 1337, `{"response":1337}`},
|
||||
{"int sub-zero", -1, `{"response":-1}`},
|
||||
{"error nil", func() error { return nil }, `{"response":false}`},
|
||||
{"error", func() error { return fmt.Errorf("error response") }, `{"error":{"message":"error response"}}`},
|
||||
{"value + error", func() (interface{}, error) { return "string response", fmt.Errorf("error response") }, `{"error":{"message":"error response"}}`},
|
||||
{"empty value + error", func() (interface{}, error) { return "", fmt.Errorf("error response") }, `{"error":{"message":"error response"}}`},
|
||||
{"value + empty error", func() (interface{}, error) { return "string response", nil }, `{"response":"string response"}`},
|
||||
{"success default", Success(), `{"success":{"message":"OK"}}`},
|
||||
{"ok", OK(), `{"success":{"message":"OK"}}`},
|
||||
{"success custom", Success("string"), `{"success":{"message":"string"}}`},
|
||||
{"error stdlib", fmt.Errorf("string"), `{"error":{"message":"string"}}`},
|
||||
{"error stdlib nil", func() interface{} { return func() error { return nil }() }(), `{"response":false}`},
|
||||
{"func json nil", func() ([]byte, error) { return json.Marshal(nil) }, `null`},
|
||||
{"func json false", func() ([]byte, error) { return json.Marshal(false) }, `false`},
|
||||
{"func json 0", func() ([]byte, error) { return json.Marshal(0) }, `0`},
|
||||
{"func json empty string", func() ([]byte, error) { return json.Marshal("") }, `""`},
|
||||
{"func writer/req", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("foo")) }, `foo`},
|
||||
{"custom struct", struct {
|
||||
Name string `json:"name"`
|
||||
}{"Corteza"}, `{"response":{"name":"Corteza"}}`},
|
||||
}
|
||||
|
||||
for _, c := range cc {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got := strings.TrimSpace(testResponse(c.inp))
|
||||
if got != strings.TrimSpace(c.out) {
|
||||
t.Errorf("got %#v, expected %#v", got, c.out)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user