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:
147
server/store/tests/attachments_test.go
Normal file
147
server/store/tests/attachments_test.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/id"
|
||||
"github.com/cortezaproject/corteza/server/pkg/rand"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func testAttachments(t *testing.T, s store.Attachments) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
req = require.New(t)
|
||||
|
||||
makeNew = func(nn ...string) *types.Attachment {
|
||||
name := strings.Join(nn, "")
|
||||
return &types.Attachment{
|
||||
ID: id.Next(),
|
||||
Name: "handle_" + name,
|
||||
Kind: "test-kind" + name,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
truncAndCreate = func(t *testing.T) (*require.Assertions, *types.Attachment) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateAttachments(ctx))
|
||||
attachment := makeNew()
|
||||
req.NoError(s.CreateAttachment(ctx, attachment))
|
||||
return req, attachment
|
||||
}
|
||||
|
||||
truncAndFill = func(t *testing.T, l int) (*require.Assertions, types.AttachmentSet) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateAttachments(ctx))
|
||||
|
||||
set := make([]*types.Attachment, l)
|
||||
|
||||
for i := 0; i < l; i++ {
|
||||
set[i] = makeNew(string(rand.Bytes(10)))
|
||||
}
|
||||
|
||||
req.NoError(s.CreateAttachment(ctx, set...))
|
||||
return req, set
|
||||
}
|
||||
)
|
||||
|
||||
t.Run("create", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.CreateAttachment(ctx, makeNew()))
|
||||
})
|
||||
|
||||
t.Run("lookup by ID", func(t *testing.T) {
|
||||
req, att := truncAndCreate(t)
|
||||
fetched, err := s.LookupAttachmentByID(ctx, att.ID)
|
||||
req.NoError(err)
|
||||
req.Equal(att.ID, fetched.ID)
|
||||
req.NotNil(fetched.CreatedAt)
|
||||
req.Nil(fetched.UpdatedAt)
|
||||
req.Nil(fetched.DeletedAt)
|
||||
})
|
||||
|
||||
t.Run("update", func(t *testing.T) {
|
||||
req, att := truncAndCreate(t)
|
||||
att.Url = "url"
|
||||
req.NoError(s.UpdateAttachment(ctx, att))
|
||||
fetched, err := s.LookupAttachmentByID(ctx, att.ID)
|
||||
req.NoError(err)
|
||||
req.Equal(att.ID, fetched.ID)
|
||||
req.Equal("url", fetched.Url)
|
||||
})
|
||||
|
||||
t.Run("upsert", func(t *testing.T) {
|
||||
t.Run("existing", func(t *testing.T) {
|
||||
req, att := truncAndCreate(t)
|
||||
att.Url = "url"
|
||||
|
||||
req.NoError(s.UpsertAttachment(ctx, att))
|
||||
|
||||
upserted, err := s.LookupAttachmentByID(ctx, att.ID)
|
||||
req.NoError(err)
|
||||
req.Equal(att.Name, upserted.Name)
|
||||
})
|
||||
|
||||
t.Run("new", func(t *testing.T) {
|
||||
att := makeNew("upsert me", "upsert-me")
|
||||
|
||||
req.NoError(s.UpsertAttachment(ctx, att))
|
||||
|
||||
upserted, err := s.LookupAttachmentByID(ctx, att.ID)
|
||||
req.NoError(err)
|
||||
req.Equal(att.Name, upserted.Name)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("delete", func(t *testing.T) {
|
||||
t.Run("by Attachment", func(t *testing.T) {
|
||||
req, att := truncAndCreate(t)
|
||||
req.NoError(s.DeleteAttachment(ctx, att))
|
||||
_, err := s.LookupAttachmentByID(ctx, att.ID)
|
||||
req.EqualError(err, store.ErrNotFound.Error())
|
||||
})
|
||||
|
||||
t.Run("by ID", func(t *testing.T) {
|
||||
req, att := truncAndCreate(t)
|
||||
req.NoError(s.DeleteAttachmentByID(ctx, att.ID))
|
||||
_, err := s.LookupAttachmentByID(ctx, att.ID)
|
||||
req.EqualError(err, store.ErrNotFound.Error())
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("search", func(t *testing.T) {
|
||||
t.Run("by kind", func(t *testing.T) {
|
||||
req, prefill := truncAndFill(t, 5)
|
||||
|
||||
set, f, err := s.SearchAttachments(ctx, types.AttachmentFilter{Kind: prefill[0].Kind})
|
||||
req.NoError(err)
|
||||
req.Equal(prefill[0].Kind, f.Kind)
|
||||
req.Len(set, 1)
|
||||
})
|
||||
|
||||
t.Run("with check", func(t *testing.T) {
|
||||
req, prefill := truncAndFill(t, 5)
|
||||
|
||||
set, _, err := s.SearchAttachments(ctx, types.AttachmentFilter{
|
||||
Check: func(attachment *types.Attachment) (bool, error) {
|
||||
return attachment.Kind == prefill[0].Kind, nil
|
||||
},
|
||||
})
|
||||
|
||||
req.NoError(err)
|
||||
req.Len(set, 1)
|
||||
req.Equal(prefill[0].Kind, set[0].Kind)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("ordered search", func(t *testing.T) {
|
||||
t.Skip("not implemented")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user