MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / TestVerifyChecksum

Function TestVerifyChecksum

internal/update/update_test.go:318–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

316}
317
318func TestVerifyChecksum(t *testing.T) {
319 // Create a temp file with known content
320 dir := t.TempDir()
321 filePath := filepath.Join(dir, "binary")
322 content := []byte("test binary content")
323 os.WriteFile(filePath, content, 0o644)
324
325 // Calculate expected hash
326 h := sha256.Sum256(content)
327 expectedHash := hex.EncodeToString(h[:])
328
329 // Serve checksum
330 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
331 fmt.Fprintf(w, "%s binary\n", expectedHash)
332 }))
333 defer srv.Close()
334
335 if err := verifyChecksum(filePath, srv.URL); err != nil {
336 t.Errorf("expected checksum verification to pass: %v", err)
337 }
338}
339
340func TestVerifyChecksum_Mismatch(t *testing.T) {
341 dir := t.TempDir()

Callers

nothing calls this directly

Calls 1

verifyChecksumFunction · 0.85

Tested by

no test coverage detected