Artifact e1c55825eb69914df95aec485a0d915628649c3c9e29049ae26b0ec3c6976faa:
- File
repo_hash_policy_test.go
— part of check-in
[feea6a1614]
at
2026-10-13 10:59:56
on branch main
— feat(repo): set the hash policy by name (#408)
artifact-format-01 7.1 (AF-7.1-2) matches policy value strings case-sensitively and exactly and makes an unrecognized value fatal. No surface took a value string, so the row stayed partial.
Repo.SetHashPolicy takes sha1, auto, sha3, sha3-only or shun-sha1, as fossil's hash-policy command does with fossil_strcmp, stores the ordinal, and refuses any other string without touching the stored policy. Auto in a repository that already holds a SHA3 artifact stores sha3 (7.3).
New conformance cases drive every name, wrong-case names, unknown names and the empty name through it, and the AF-7.1-2 scope note is dropped. (user: [email protected], size: 800) [annotate] [blame] [check-ins using]
package libfossil import ( "path/filepath" "testing" _ "github.com/danmestas/go-libfossil/internal/testdriver" ) // SetHashPolicy takes the policy names of artifact-format-01 Table 7 and // stores their ordinal; a wrong-case name is refused and changes nothing. func TestSetHashPolicy(t *testing.T) { r, err := Create(filepath.Join(t.TempDir(), "test.fossil"), CreateOpts{User: "test"}) if err != nil { t.Fatal(err) } defer r.Close() if err := r.SetHashPolicy("sha3-only"); err != nil { t.Fatalf("SetHashPolicy(sha3-only): %v", err) } if err := r.SetHashPolicy("SHA1"); err == nil { t.Fatal("SetHashPolicy(SHA1) succeeded, want an error") } got, err := r.Config("hash-policy") if err != nil { t.Fatal(err) } if got != "3" { t.Errorf("hash-policy = %q, want 3", got) } }