Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/storage/storage_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 1675031db74316e100782d063e9eda1a597fe3a1 |
| Branch | workstream-a-opportunity-intelligence |
| Path or archive member | internal/platform/storage/storage_test.go |
| Original SHA-256 | b23595402f8ed12f09378de3b2ccaaa0ed9c0cb854a9dc7f758a8c3537a97221 |
| Git blob SHA | 705cf7ad247244d6319bc1344c8a50687d7e4a64 |
| Reading-copy SHA-256 | b23595402f8ed12f09378de3b2ccaaa0ed9c0cb854a9dc7f758a8c3537a97221 |
Every recorded occurrence
These 7 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-a-opportunity-intelligence | 1675031db74316e100782d063e9eda1a597fe3a1 | Open original |
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-d-command-center | 255e7d1d420abf5e277d0cd8c9b14f6f72b6acb9 | Open original |
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-e-commercial-stubs | 4437da660539284a400ee380b9b427a300c369ee | Open original |
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-b-sam-contract-awards | d5101cceb98e70000cebb31d3e7ac73d747d3a6d | Open original |
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-d-command-center | 255e7d1d420abf5e277d0cd8c9b14f6f72b6acb9 | Open original |
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-a-opportunity-intelligence | 1675031db74316e100782d063e9eda1a597fe3a1 | Open original |
| Janady13/missionmatch / internal/platform/storage/storage_test.go | workstream-e-commercial-stubs | 4437da660539284a400ee380b9b427a300c369ee | Open original |
Recovered source transcript
Download complete source text ↓87 lines · 2.2 KB
package storage
import (
"context"
"errors"
"os"
"path/filepath"
"testing"
)
func TestLocalStoreRoundTrip(t *testing.T) {
ctx := context.Background()
s, err := NewLocal(t.TempDir())
if err != nil {
t.Fatalf("NewLocal: %v", err)
}
key := "opportunity_records/sam.gov/abc123.json"
data := []byte(`{"noticeId":"abc123"}`)
if err := s.Put(ctx, key, data); err != nil {
t.Fatalf("Put: %v", err)
}
got, err := s.Get(ctx, key)
if err != nil {
t.Fatalf("Get: %v", err)
}
if string(got) != string(data) {
t.Fatalf("round trip mismatch: %s", got)
}
ok, err := s.Exists(ctx, key)
if err != nil || !ok {
t.Fatalf("Exists = %v, %v", ok, err)
}
if err := s.Delete(ctx, key); err != nil {
t.Fatalf("Delete: %v", err)
}
if _, err := s.Get(ctx, key); !errors.Is(err, ErrNotFound) {
t.Fatalf("after delete want ErrNotFound, got %v", err)
}
}
func TestLocalStoreRejectsTraversal(t *testing.T) {
ctx := context.Background()
root := t.TempDir()
s, err := NewLocal(root)
if err != nil {
t.Fatalf("NewLocal: %v", err)
}
for _, key := range []string{"../escape.json", "/etc/passwd", "a/../../escape", "", "..", "."} {
if err := s.Put(ctx, key, []byte("x")); err == nil {
t.Fatalf("Put(%q) should have been rejected", key)
}
}
if _, err := os.Stat(filepath.Join(filepath.Dir(root), "escape.json")); err == nil {
t.Fatal("a traversal key wrote outside the root")
}
}
func TestMemoryStoreRoundTrip(t *testing.T) {
ctx := context.Background()
s := NewMemory()
if err := s.Put(ctx, "k/a.json", []byte("v")); err != nil {
t.Fatalf("Put: %v", err)
}
got, err := s.Get(ctx, "k/a.json")
if err != nil || string(got) != "v" {
t.Fatalf("Get = %q, %v", got, err)
}
if _, err := s.Get(ctx, "missing"); !errors.Is(err, ErrNotFound) {
t.Fatalf("want ErrNotFound, got %v", err)
}
// A returned slice must be a copy: mutating it must not change the stored bytes.
got[0] = 'X'
again, _ := s.Get(ctx, "k/a.json")
if string(again) != "v" {
t.Fatalf("stored value was aliased: %q", again)
}
}
func TestSHA256HexStable(t *testing.T) {
if SHA256Hex([]byte("payload")) != SHA256Hex([]byte("payload")) {
t.Fatal("sha not stable")
}
if SHA256Hex([]byte("a")) == SHA256Hex([]byte("b")) {
t.Fatal("sha collision")
}
}