fix(sources): store the acting org on source creation
This commit is contained in:
1 parent
b8bedf4d7b
commit
d6b693a9b2
4 files changed
+51
-7
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package postgres_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/domain/source"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgstore"
|
||||
)
|
||||
|
||||
// TestInsertSourceKeepsActingOrg pins that a source created while acting in a
|
||||
// non-default org is owned by that org, so its captures inherit the org.
|
||||
func TestInsertSourceKeepsActingOrg(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
db := pgstore.Open(t)
|
||||
eda := postgres.NewEDA(db.Pool, nil)
|
||||
if err := eda.InsertSource(org.WithOrg(ctx, "acme"), source.Source{Path: "acme-hook", Signing: source.SigningUnsigned}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var owner, workspace string
|
||||
if err := db.Pool.QueryRow(ctx, "SELECT org_id, workspace_id FROM sources WHERE path=$1", "acme-hook").Scan(&owner, &workspace); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if owner != "acme" || workspace != string(org.DefaultWorkspaceID) {
|
||||
t.Fatalf("source owner %s/%s, want acme/%s", owner, workspace, org.DefaultWorkspaceID)
|
||||
}
|
||||
// Lookup stays global: the capture receiver resolves by path alone.
|
||||
got, err := eda.GetSource(ctx, "acme-hook")
|
||||
if err != nil || got == nil {
|
||||
t.Fatalf("GetSource = %#v, err %v", got, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user