mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package sbomrecord
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/commerce/datastore"
|
|
)
|
|
|
|
func testDB() *datastore.Datastore { return datastore.New(context.Background()) }
|
|
|
|
func TestKind(t *testing.T) {
|
|
if (&SBOMRecord{}).Kind() != "sbom-record" {
|
|
t.Fatalf("kind = %q", (&SBOMRecord{}).Kind())
|
|
}
|
|
}
|
|
|
|
func TestSaveLoad_RoundTripsComponents(t *testing.T) {
|
|
s := New(testDB())
|
|
s.ImageRef = "ghcr.io/hanzoai/commerce:1.0.0"
|
|
s.ImageDigest = "sha256:abc"
|
|
s.Service = "commerce"
|
|
s.Components = []Component{
|
|
{PURL: "pkg:golang/github.com/gin-gonic/[email protected]", Name: "gin", Ecosystem: "golang", Version: "v1.12.0", Scope: "direct"},
|
|
{PURL: "pkg:npm/[email protected]", Name: "react", Ecosystem: "npm", Version: "18.3.1", Scope: "transitive"},
|
|
}
|
|
|
|
ps, err := s.Save()
|
|
if err != nil {
|
|
t.Fatalf("save: %v", err)
|
|
}
|
|
if s.ComponentCount != 2 {
|
|
t.Fatalf("ComponentCount = %d, want 2", s.ComponentCount)
|
|
}
|
|
if s.Components_ == "" {
|
|
t.Fatal("Components_ JSON blob not populated on Save")
|
|
}
|
|
|
|
// Load into a fresh record from the saved properties.
|
|
loaded := New(testDB())
|
|
if err := loaded.Load(ps); err != nil {
|
|
t.Fatalf("load: %v", err)
|
|
}
|
|
if len(loaded.Components) != 2 {
|
|
t.Fatalf("loaded %d components, want 2", len(loaded.Components))
|
|
}
|
|
if loaded.Components[0].PURL != "pkg:golang/github.com/gin-gonic/[email protected]" {
|
|
t.Fatalf("loaded component PURL = %q", loaded.Components[0].PURL)
|
|
}
|
|
if loaded.Format != "cyclonedx" {
|
|
t.Fatalf("default format = %q, want cyclonedx", loaded.Format)
|
|
}
|
|
}
|