Builds: design 47 G §464, §680 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
)
|
|
|
|
// Design 47 G §465, §373 (BN7): a fetch naming builds reads each member from the artifact store by its digest, checks the
|
|
// bytes and lays it in node_modules as the package named; a mismatch, or a store that does not answer, fails naming it.
|
|
func TestAFetchLaysAGroupMembersBuildFromTheArtifactStore(t *testing.T) {
|
|
tgz := tgzOf(t, "@novox/lib", "0.0.0")
|
|
digest := digestOf(tgz)
|
|
store := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/v2/lib/pkg/blobs/"+digest {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
w.Write(tgz)
|
|
}))
|
|
defer store.Close()
|
|
m := &Module{ArtifactStoreFile: filepath.Join(t.TempDir(), "artifact-store.json")}
|
|
os.WriteFile(m.ArtifactStoreFile, []byte(`{"at":"`+strings.TrimPrefix(store.URL, "http://")+`"}`), 0o600)
|
|
member := sdkstep.FetchBuild{Package: "@novox/lib", Module: "lib", Artifact: "pkg", Digest: digest}
|
|
|
|
got, err := m.readBuilds(context.Background(), []sdkstep.FetchBuild{member})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dir := t.TempDir()
|
|
if err := m.layBuilds(dir, got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if b, err := os.ReadFile(filepath.Join(dir, "node_modules", "@novox", "lib", "dist", "index.js")); err != nil || !strings.Contains(string(b), "0.0.0") {
|
|
t.Fatalf("the member was not laid: %q, %v", b, err)
|
|
}
|
|
if !namesPackage(got, "@novox/lib") || namesPackage(got, "@novox/other") {
|
|
t.Error("namesPackage is wrong")
|
|
}
|
|
bad := member
|
|
bad.Digest = "sha256:" + strings.Repeat("0", 64)
|
|
for _, c := range []sdkstep.FetchBuild{bad, {Package: "@novox/lib", Module: "lib", Artifact: "missing", Digest: digest}} {
|
|
if _, err := m.readBuilds(context.Background(), []sdkstep.FetchBuild{c}); err == nil || !strings.Contains(err.Error(), "@novox/lib") {
|
|
t.Errorf("member %+v: error %v", c, err)
|
|
}
|
|
}
|
|
store.Close()
|
|
if _, err := m.readBuilds(context.Background(), []sdkstep.FetchBuild{member}); err == nil || !strings.Contains(err.Error(), "@novox/lib") {
|
|
t.Errorf("a store that does not answer: %v", err)
|
|
}
|
|
}
|