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:
318
server/tests/compose/chart_test.go
Normal file
318
server/tests/compose/chart_test.go
Normal file
@@ -0,0 +1,318 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/compose/service"
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/id"
|
||||
labelTypes "github.com/cortezaproject/corteza/server/pkg/label/types"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/tests/helpers"
|
||||
jsonpath "github.com/steinfletcher/apitest-jsonpath"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func (h helper) clearCharts() {
|
||||
h.clearNamespaces()
|
||||
h.noError(store.TruncateComposeCharts(context.Background(), service.DefaultStore))
|
||||
}
|
||||
|
||||
func (h helper) makeChart(ns *types.Namespace, name string) *types.Chart {
|
||||
res := &types.Chart{
|
||||
ID: id.Next(),
|
||||
CreatedAt: time.Now(),
|
||||
Name: name,
|
||||
Handle: name,
|
||||
NamespaceID: ns.ID,
|
||||
}
|
||||
|
||||
h.noError(store.CreateComposeChart(context.Background(), service.DefaultStore, res))
|
||||
return res
|
||||
}
|
||||
|
||||
func (h helper) lookupChartByID(ID uint64) *types.Chart {
|
||||
res, err := store.LookupComposeChartByID(context.Background(), service.DefaultStore, ID)
|
||||
h.noError(err)
|
||||
return res
|
||||
}
|
||||
|
||||
func TestChartRead(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "read")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
m := h.makeChart(ns, "some-chart")
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/namespace/%d/chart/%d", ns.ID, m.ID)).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.Equal(`$.response.name`, m.Name)).
|
||||
Assert(jsonpath.Equal(`$.response.chartID`, fmt.Sprintf("%d", m.ID))).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartReadByHandle(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "read")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
c := h.makeChart(ns, "some-chart")
|
||||
|
||||
cbh, err := service.DefaultChart.FindByHandle(h.secCtx(), ns.ID, c.Handle)
|
||||
|
||||
h.noError(err)
|
||||
h.a.NotNil(cbh)
|
||||
h.a.Equal(cbh.ID, c.ID)
|
||||
h.a.Equal(cbh.Handle, c.Handle)
|
||||
}
|
||||
|
||||
func TestChartList(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
|
||||
h.makeChart(ns, "chart1")
|
||||
h.makeChart(ns, "chart2")
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/namespace/%d/chart/", ns.ID)).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartList_filterForbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
|
||||
h.makeChart(ns, "chart")
|
||||
f := h.makeChart(ns, "chart_forbidden")
|
||||
|
||||
helpers.DenyMe(h, f.RbacResource(), "read")
|
||||
|
||||
h.apiInit().
|
||||
Get(fmt.Sprintf("/namespace/%d/chart/", ns.ID)).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
Assert(jsonpath.NotPresent(`$.response.set[? @.name=="chart_forbidden"]`)).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartCreateForbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/namespace/%d/chart/", ns.ID)).
|
||||
Header("Accept", "application/json").
|
||||
FormData("name", "some-chart").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("chart.errors.notAllowedToCreate")).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartCreate(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "chart.create")
|
||||
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/namespace/%d/chart/", ns.ID)).
|
||||
FormData("name", "some-chart").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartUpdateForbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
m := h.makeChart(ns, "some-chart")
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/namespace/%d/chart/%d", ns.ID, m.ID)).
|
||||
Header("Accept", "application/json").
|
||||
FormData("name", "changed-name").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("chart.errors.notAllowedToUpdate")).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartUpdate(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
res := h.makeChart(ns, "some-chart")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "update")
|
||||
|
||||
h.apiInit().
|
||||
Post(fmt.Sprintf("/namespace/%d/chart/%d", ns.ID, res.ID)).
|
||||
FormData("name", "changed-name").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
|
||||
res = h.lookupChartByID(res.ID)
|
||||
h.a.NotNil(res)
|
||||
h.a.Equal(res.Name, "changed-name")
|
||||
}
|
||||
|
||||
func TestChartDeleteForbidden(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "read")
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
m := h.makeChart(ns, "some-chart")
|
||||
|
||||
h.apiInit().
|
||||
Delete(fmt.Sprintf("/namespace/%d/chart/%d", ns.ID, m.ID)).
|
||||
Header("Accept", "application/json").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertError("chart.errors.notAllowedToDelete")).
|
||||
End()
|
||||
}
|
||||
|
||||
func TestChartDelete(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "read")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "delete")
|
||||
|
||||
ns := h.makeNamespace("some-namespace")
|
||||
res := h.makeChart(ns, "some-chart")
|
||||
|
||||
h.apiInit().
|
||||
Delete(fmt.Sprintf("/namespace/%d/chart/%d", ns.ID, res.ID)).
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End()
|
||||
|
||||
res = h.lookupChartByID(res.ID)
|
||||
h.a.NotNil(res.DeletedAt)
|
||||
}
|
||||
|
||||
func TestChartLabels(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
h.clearCharts()
|
||||
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "read", "charts.search")
|
||||
helpers.AllowMe(h, types.NamespaceRbacResource(0), "chart.create")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "read")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "update")
|
||||
helpers.AllowMe(h, types.ChartRbacResource(0, 0), "delete")
|
||||
|
||||
var (
|
||||
ns = h.makeNamespace("some-namespace")
|
||||
ID uint64
|
||||
)
|
||||
|
||||
t.Run("create", func(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
payload = &types.Chart{}
|
||||
)
|
||||
|
||||
helpers.SetLabelsViaAPI(h.apiInit(), t,
|
||||
fmt.Sprintf("/namespace/%d/chart/", ns.ID),
|
||||
types.Chart{Labels: map[string]labelTypes.LabelValue{"foo": {Val: "bar"}, "bar": {Val: "42"}}},
|
||||
payload,
|
||||
)
|
||||
req.NotZero(payload.ID)
|
||||
|
||||
h.a.Equal(payload.Labels["foo"].Val, "bar",
|
||||
"labels must contain foo with value bar")
|
||||
h.a.Equal(payload.Labels["bar"].Val, "42",
|
||||
"labels must contain bar with value 42")
|
||||
req.Equal(helpers.LabelsToStrings(payload.Labels), helpers.LabelsToStrings(helpers.LoadLabelsFromStore(t, service.DefaultStore, payload.LabelResourceKind(), payload.ID)),
|
||||
"response must match stored labels")
|
||||
|
||||
ID = payload.ID
|
||||
})
|
||||
|
||||
t.Run("update", func(t *testing.T) {
|
||||
if ID == 0 {
|
||||
t.Skip("label/create test not ran")
|
||||
}
|
||||
|
||||
var (
|
||||
req = require.New(t)
|
||||
payload = &types.Chart{}
|
||||
)
|
||||
|
||||
helpers.SetLabelsViaAPI(h.apiInit(), t,
|
||||
fmt.Sprintf("/namespace/%d/chart/%d", ns.ID, ID),
|
||||
types.Chart{Labels: map[string]labelTypes.LabelValue{"foo": {Val: "baz"}, "baz": {Val: "123"}}},
|
||||
payload,
|
||||
)
|
||||
req.NotZero(payload.ID)
|
||||
req.Nil(payload.UpdatedAt, "updatedAt must not change after changing labels")
|
||||
|
||||
req.Equal(payload.Labels["foo"].Val, "baz",
|
||||
"labels must contain foo with value baz")
|
||||
req.NotContains(payload.Labels, "bar",
|
||||
"labels must not contain bar")
|
||||
req.Equal(payload.Labels["baz"].Val, "123",
|
||||
"labels must contain baz with value 123")
|
||||
req.Equal(helpers.LabelsToStrings(payload.Labels), helpers.LabelsToStrings(helpers.LoadLabelsFromStore(t, service.DefaultStore, payload.LabelResourceKind(), payload.ID)),
|
||||
"response must match stored labels")
|
||||
})
|
||||
|
||||
t.Run("search", func(t *testing.T) {
|
||||
if ID == 0 {
|
||||
t.Skip("label/create test not ran")
|
||||
}
|
||||
|
||||
var (
|
||||
req = require.New(t)
|
||||
set = types.ChartSet{}
|
||||
)
|
||||
|
||||
helpers.SearchWithLabelsViaAPI(h.apiInit(), t,
|
||||
fmt.Sprintf("/namespace/%d/chart/", ns.ID),
|
||||
&set, url.Values{"labels": []string{"baz=123"}},
|
||||
)
|
||||
req.NotEmpty(set)
|
||||
req.NotNil(set.FindByID(ID))
|
||||
req.NotNil(set.FindByID(ID).Labels)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user