feat(platform): add the notification inbox and deterministic match search
This commit is contained in:
1 parent
5edff21d2d
commit
0b11021b16
169 files changed
+17083
-443
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package policypublish
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
"lincodex/backend/internal/usecase/policy"
|
||||
)
|
||||
|
||||
type extenderFake struct {
|
||||
result policy.MatchingResult
|
||||
err error
|
||||
author domain.PolicyAuthor
|
||||
}
|
||||
|
||||
func (extender *extenderFake) EnsureDemoMatchingSection(_ context.Context, author domain.PolicyAuthor) (policy.MatchingResult, error) {
|
||||
extender.author = author
|
||||
return extender.result, extender.err
|
||||
}
|
||||
|
||||
func TestParseRequiresTheMatchingTrackAndAnOperatorHandle(t *testing.T) {
|
||||
command, err := Parse([]string{"matching", "--actor", "operator:night"})
|
||||
if err != nil || command.Author != "operator:night" {
|
||||
t.Fatalf("Parse(valid) = %+v, %v", command, err)
|
||||
}
|
||||
for _, args := range [][]string{
|
||||
nil, {"list"}, {"matching"}, {"matching", "--actor", "alice"}, {"matching", "--actor", "system:demo-seed"},
|
||||
{"matching", "--actor", "operator:night", "extra"},
|
||||
} {
|
||||
if _, err := Parse(args); err == nil {
|
||||
t.Errorf("Parse(%v) accepted invalid arguments", args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecutePrintsOnlyTheVersionAndMapsFailuresToSafeMessages(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
extender := &extenderFake{}
|
||||
if err := Execute(context.Background(), Command{Author: "operator:night"}, extender, &output); err != nil {
|
||||
t.Fatalf("Execute() error = %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(output.String(), "already present: product policy version 0") || extender.author != "operator:night" {
|
||||
t.Fatalf("output = %q, author %q", output.String(), extender.author)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
err error
|
||||
want string
|
||||
}{
|
||||
{policy.ErrNotDemoPolicy, "not a demonstration version"},
|
||||
{outbound.ErrPolicyVersionNotFound, "no version yet"},
|
||||
{policy.ErrPolicyChanged, "run the command again"},
|
||||
{errors.New("pq: password authentication failed for user x"), "policy publication failed"},
|
||||
} {
|
||||
err := Execute(context.Background(), Command{Author: "operator:night"}, &extenderFake{err: test.err}, &bytes.Buffer{})
|
||||
if err == nil || !strings.Contains(err.Error(), test.want) || strings.Contains(err.Error(), "password") {
|
||||
t.Errorf("Execute(%v) error = %v, want a safe message containing %q", test.err, err, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user