MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestPublishedManifestMatchesAssetName

Function TestPublishedManifestMatchesAssetName

internal/update/drift_test.go:109–150  ·  view source on GitHub ↗

TestPublishedManifestMatchesAssetName is opt-in: point CODEHAMR_CHECK_MANIFEST at a goreleaser checksums file (CI sets it to dist/codehamr_checksums.txt after a release build) and it asserts the published asset names are EXACTLY the set assetName produces. This is the only check that exercises real

(t *testing.T)

Source from the content-addressed store, hash-verified

107// of which the hermetic test above can see. Skips when the env var is unset, so
108// the default `go test ./...` never needs goreleaser or the network.
109func TestPublishedManifestMatchesAssetName(t *testing.T) {
110 path := os.Getenv("CODEHAMR_CHECK_MANIFEST")
111 if path == "" {
112 t.Skip("set CODEHAMR_CHECK_MANIFEST=<checksums.txt> to compare published asset names against assetName")
113 }
114 f, err := os.Open(path)
115 if err != nil {
116 t.Fatalf("open manifest %s: %v", path, err)
117 }
118 defer f.Close()
119
120 published := map[string]bool{}
121 sc := bufio.NewScanner(f)
122 for sc.Scan() {
123 fields := strings.Fields(strings.TrimSpace(sc.Text()))
124 if len(fields) < 2 {
125 continue
126 }
127 published[fields[len(fields)-1]] = true
128 }
129 if err := sc.Err(); err != nil {
130 t.Fatal(err)
131 }
132 if len(published) == 0 {
133 t.Fatalf("manifest %s listed no assets", path)
134 }
135
136 want := map[string]bool{}
137 for _, name := range assetNameSupported(goreleaserMatrix(t)) {
138 want[name] = true
139 }
140 for name := range want {
141 if !published[name] {
142 t.Errorf("assetName produces %q but it is NOT in the published manifest - that platform's auto-update would 404 / find no checksum row", name)
143 }
144 }
145 for name := range published {
146 if !want[name] {
147 t.Errorf("published manifest lists %q which assetName never produces - a stale/renamed asset auto-update can't reach", name)
148 }
149 }
150}

Callers

nothing calls this directly

Calls 2

assetNameSupportedFunction · 0.85
goreleaserMatrixFunction · 0.85

Tested by

no test coverage detected