diff --git a/instantiated_test.go b/instantiated_test.go index 68c95f3..1a5c397 100644 --- a/instantiated_test.go +++ b/instantiated_test.go @@ -26,14 +26,7 @@ func TestInstantiated(t *testing.T) { {"unexpected quotes short", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedUnexpectedQuotes}}, {"not absolute", nil, &nix.MalformedInstantiatedError{Type: nix.InstantiatedNotAbsolute}}, - {"good segment", []string{ - "/nix/store/3zilrlmq7r6rpzfd94mwss32b62yinj5-bootstrap-stage0-stdenv-linux.drv", - "/nix/store/7yfwy95p6lcdpljdajs5aw10h6q0sfx0-update-autotools-gnu-config-scripts-hook.drv", - "/nix/store/bamwxswxacs3cjdcydv0z7bj22d7g2kc-config.guess-948ae97.drv", - "/nix/store/gyks6vvl7x0gq214ldjhi3w4rg37nh8i-zlib-1.3.1.tar.gz.drv", - "/nix/store/nbsdqpfzh1jlpmh95s69b3iivfcvv3lh-config.sub-948ae97.drv", - "/nix/store/ysp83x9nrks28zkblqmnc1s1kb68dr69-gnu-config-2024-01-01.drv", - }, nil}, + {"good segment", segmentWant, nil}, {"getchoo atlas", getchooAtlasInstantiated, nil}, {"getchoo glados", getchooGladosInstantiated, nil}, @@ -93,12 +86,6 @@ func stubInstantiatedEvaluator(args []string) error { } func TestInstantiatedDecoderStopEarly(t *testing.T) { - want := []string{ - "/nix/store/gyks6vvl7x0gq214ldjhi3w4rg37nh8i-zlib-1.3.1.tar.gz.drv", - "/nix/store/bamwxswxacs3cjdcydv0z7bj22d7g2kc-config.guess-948ae97.drv", - "/nix/store/nbsdqpfzh1jlpmh95s69b3iivfcvv3lh-config.sub-948ae97.drv", - } - decoder := nix.NewInstantiatedDecoder(strings.NewReader(segmentPrefix+segmentBody+segmentSuffix), os.Stderr) counter := 3 got := make([]string, 0, counter) @@ -110,8 +97,8 @@ func TestInstantiatedDecoderStopEarly(t *testing.T) { } } - if !slices.Equal(got, want) { - t.Errorf("Instantiated: %#v, want %#v", got, want) + if !slices.Equal(got, segmentEarly) { + t.Errorf("Instantiated: %#v, want %#v", got, segmentEarly) } } diff --git a/sample_getchoo_atlas_test.go b/sample_getchoo_atlas_test.go deleted file mode 100644 index 185105c..0000000 --- a/sample_getchoo_atlas_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package nix_test - -import _ "embed" - -// github:getchoo/borealis#atlas - -var ( - getchooAtlasOut = string(sampleMustGunzip(getchooAtlasOutGzip)) - //go:embed testdata/getchoo_atlas.gz - getchooAtlasOutGzip []byte - - getchooAtlasInstantiated = sampleSplitPaths(sampleMustGunzip(getchooAtlasInstantiatedGzip)) - //go:embed testdata/instantiated/getchoo_atlas.gz - getchooAtlasInstantiatedGzip []byte - - getchooAtlasShow = sampleMustGunzip(getchooAtlasShowGzip) - //go:embed testdata/derivation/show_getchoo_atlas.json.gz - getchooAtlasShowGzip []byte - - getchooAtlasCollective = sampleSplitPaths(sampleMustGunzip(getchooAtlasCollectiveGzip)) - //go:embed testdata/derivation/collect_getchoo_atlas.gz - getchooAtlasCollectiveGzip []byte - - getchooAtlasStdin = string(sampleMustGunzip(getchooAtlasStdinGzip)) - //go:embed testdata/format/stdin_getchoo_atlas.gz - getchooAtlasStdinGzip []byte -) diff --git a/sample_getchoo_glados_test.go b/sample_getchoo_glados_test.go deleted file mode 100644 index c19f5ec..0000000 --- a/sample_getchoo_glados_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package nix_test - -import _ "embed" - -// github:getchoo/borealis#glados - -var ( - getchooGladosOut = string(sampleMustGunzip(getchooGladosOutGzip)) - //go:embed testdata/getchoo_glados.gz - getchooGladosOutGzip []byte - - getchooGladosInstantiated = sampleSplitPaths(sampleMustGunzip(getchooGladosInstantiatedGzip)) - //go:embed testdata/instantiated/getchoo_glados.gz - getchooGladosInstantiatedGzip []byte - - getchooGladosShow = sampleMustGunzip(getchooGladosShowGzip) - //go:embed testdata/derivation/show_getchoo_glados.json.gz - getchooGladosShowGzip []byte - - getchooGladosCollective = sampleSplitPaths(sampleMustGunzip(getchooGladosCollectiveGzip)) - //go:embed testdata/derivation/collect_getchoo_glados.gz - getchooGladosCollectiveGzip []byte - - getchooGladosStdin = string(sampleMustGunzip(getchooGladosStdinGzip)) - //go:embed testdata/format/stdin_getchoo_glados.gz - getchooGladosStdinGzip []byte -) diff --git a/sample_pluiedev_pappardelle_test.go b/sample_pluiedev_pappardelle_test.go deleted file mode 100644 index cf3337d..0000000 --- a/sample_pluiedev_pappardelle_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package nix_test - -import ( - _ "embed" -) - -// git+https://tangled.sh/@pluie.me/flake#pappardelle - -var ( - pluiedevPappardelleOut = string(sampleMustGunzip(pluiedevPappardelleGzip)) - //go:embed testdata/pluiedev_pappardelle.gz - pluiedevPappardelleGzip []byte - - pluiedevPappardelleInstantiated = sampleSplitPaths(sampleMustGunzip(pluiedevPappardelleInstantiatedGzip)) - //go:embed testdata/instantiated/pluiedev_pappardelle.gz - pluiedevPappardelleInstantiatedGzip []byte - - pluiedevPappardelleShow = sampleMustGunzip(pluiedevPappardelleShowGzip) - //go:embed testdata/derivation/show_pluiedev_pappardelle.json.gz - pluiedevPappardelleShowGzip []byte - - pluiedevPappardelleCollective = sampleSplitPaths(sampleMustGunzip(pluiedevPappardelleCollectiveGzip)) - //go:embed testdata/derivation/collect_pluiedev_pappardelle.gz - pluiedevPappardelleCollectiveGzip []byte - - pluiedevPappardelleStdin = string(sampleMustGunzip(pluiedevPappardelleStdinGzip)) - //go:embed testdata/format/stdin_pluiedev_pappardelle.gz - pluiedevPappardelleStdinGzip []byte -) diff --git a/sample_test.go b/sample_test.go index 9aa2424..634fa0f 100644 --- a/sample_test.go +++ b/sample_test.go @@ -3,6 +3,7 @@ package nix_test import ( "bytes" "compress/gzip" + _ "embed" "io" "strings" ) @@ -38,33 +39,23 @@ var drvShow = map[string][]byte{ "pluiedev pappardelle": pluiedevPappardelleShow, } -const ( - segmentPrefix = `evaluating file '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/development/libraries/zlib/default.nix' -evaluating file '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/fetchurl/boot.nix' -performing daemon worker op: 7 -instantiated 'zlib-1.3.1.tar.gz' -> '/nix/store/gyks6vvl7x0gq214ldjhi3w4rg37nh8i-zlib-1.3.1.tar.gz.drv' -source path '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh' is uncacheable -copying '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh' to the store... -performing daemon worker op: 7 -copied '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh' to '/nix/store/96rvfw5vlv1hwwm9sdxhdkkpjyym6p2x-update-autotools-gnu-config-scripts.sh' -copied source '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh' -> '/nix/store/96rvfw5vlv1hwwm9sdxhdkkpjyym6p2x-update-autotools-gnu-config-scripts.sh' -evaluating file '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/by-name/gn/gnu-config/package.nix' -performing daemon worker op: 7 -instantiated 'config.guess-948ae97' -> '/nix/store/bamwxswxacs3cjdcydv0z7bj22d7g2kc-config.guess-948ae97.drv' -performing daemon worker op: 7 -` +var ( + segmentPrefix = string(sampleMustGunzip(segmentPrefixGzip)) + segmentBody = string(sampleMustGunzip(segmentBodyGzip)) + segmentSuffix = string(sampleMustGunzip(segmentSuffixGzip)) + segmentWant = sampleSplitPaths(sampleMustGunzip(segmentWantGzip)) + segmentEarly = sampleSplitPaths(sampleMustGunzip(segmentEarlyGzip)) - segmentBody = `instantiated 'config.sub-948ae97' -> '/nix/store/nbsdqpfzh1jlpmh95s69b3iivfcvv3lh-config.sub-948ae97.drv'` - - segmentSuffix = ` -performing daemon worker op: 7 -instantiated 'gnu-config-2024-01-01' -> '/nix/store/ysp83x9nrks28zkblqmnc1s1kb68dr69-gnu-config-2024-01-01.drv' -performing daemon worker op: 7 -instantiated 'bootstrap-stage0-stdenv-linux' -> '/nix/store/3zilrlmq7r6rpzfd94mwss32b62yinj5-bootstrap-stage0-stdenv-linux.drv' -performing daemon worker op: 7 -instantiated 'update-autotools-gnu-config-scripts-hook' -> '/nix/store/7yfwy95p6lcdpljdajs5aw10h6q0sfx0-update-autotools-gnu-config-scripts-hook.drv' -source path '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/bintools-wrapper/ld-wrapper.sh' is uncacheable -copying '/nix/store/vdzlppvrdkz9rv14q4j02g9kpjbww2ww-source/pkgs/build-support/bintools-wrapper/ld-wrapper.sh' to the store...` + //go:embed testdata/segment/prefix.gz + segmentPrefixGzip []byte + //go:embed testdata/segment/body.gz + segmentBodyGzip []byte + //go:embed testdata/segment/suffix.gz + segmentSuffixGzip []byte + //go:embed testdata/segment/want.gz + segmentWantGzip []byte + //go:embed testdata/segment/early.gz + segmentEarlyGzip []byte ) func sampleSplitPaths(data []byte) []string { @@ -80,3 +71,75 @@ func sampleMustGunzip(data []byte) []byte { } return u } + +// github:getchoo/borealis#atlas + +var ( + getchooAtlasOut = string(sampleMustGunzip(getchooAtlasOutGzip)) + //go:embed testdata/getchoo_atlas.gz + getchooAtlasOutGzip []byte + + getchooAtlasInstantiated = sampleSplitPaths(sampleMustGunzip(getchooAtlasInstantiatedGzip)) + //go:embed testdata/instantiated/getchoo_atlas.gz + getchooAtlasInstantiatedGzip []byte + + getchooAtlasShow = sampleMustGunzip(getchooAtlasShowGzip) + //go:embed testdata/derivation/show_getchoo_atlas.json.gz + getchooAtlasShowGzip []byte + + getchooAtlasCollective = sampleSplitPaths(sampleMustGunzip(getchooAtlasCollectiveGzip)) + //go:embed testdata/derivation/collect_getchoo_atlas.gz + getchooAtlasCollectiveGzip []byte + + getchooAtlasStdin = string(sampleMustGunzip(getchooAtlasStdinGzip)) + //go:embed testdata/format/stdin_getchoo_atlas.gz + getchooAtlasStdinGzip []byte +) + +// github:getchoo/borealis#glados + +var ( + getchooGladosOut = string(sampleMustGunzip(getchooGladosOutGzip)) + //go:embed testdata/getchoo_glados.gz + getchooGladosOutGzip []byte + + getchooGladosInstantiated = sampleSplitPaths(sampleMustGunzip(getchooGladosInstantiatedGzip)) + //go:embed testdata/instantiated/getchoo_glados.gz + getchooGladosInstantiatedGzip []byte + + getchooGladosShow = sampleMustGunzip(getchooGladosShowGzip) + //go:embed testdata/derivation/show_getchoo_glados.json.gz + getchooGladosShowGzip []byte + + getchooGladosCollective = sampleSplitPaths(sampleMustGunzip(getchooGladosCollectiveGzip)) + //go:embed testdata/derivation/collect_getchoo_glados.gz + getchooGladosCollectiveGzip []byte + + getchooGladosStdin = string(sampleMustGunzip(getchooGladosStdinGzip)) + //go:embed testdata/format/stdin_getchoo_glados.gz + getchooGladosStdinGzip []byte +) + +// git+https://tangled.sh/@pluie.me/flake#pappardelle + +var ( + pluiedevPappardelleOut = string(sampleMustGunzip(pluiedevPappardelleGzip)) + //go:embed testdata/pluiedev_pappardelle.gz + pluiedevPappardelleGzip []byte + + pluiedevPappardelleInstantiated = sampleSplitPaths(sampleMustGunzip(pluiedevPappardelleInstantiatedGzip)) + //go:embed testdata/instantiated/pluiedev_pappardelle.gz + pluiedevPappardelleInstantiatedGzip []byte + + pluiedevPappardelleShow = sampleMustGunzip(pluiedevPappardelleShowGzip) + //go:embed testdata/derivation/show_pluiedev_pappardelle.json.gz + pluiedevPappardelleShowGzip []byte + + pluiedevPappardelleCollective = sampleSplitPaths(sampleMustGunzip(pluiedevPappardelleCollectiveGzip)) + //go:embed testdata/derivation/collect_pluiedev_pappardelle.gz + pluiedevPappardelleCollectiveGzip []byte + + pluiedevPappardelleStdin = string(sampleMustGunzip(pluiedevPappardelleStdinGzip)) + //go:embed testdata/format/stdin_pluiedev_pappardelle.gz + pluiedevPappardelleStdinGzip []byte +) diff --git a/testdata/segment/body.gz b/testdata/segment/body.gz new file mode 100644 index 0000000..92cdba3 Binary files /dev/null and b/testdata/segment/body.gz differ diff --git a/testdata/segment/early.gz b/testdata/segment/early.gz new file mode 100644 index 0000000..35944ab Binary files /dev/null and b/testdata/segment/early.gz differ diff --git a/testdata/segment/prefix.gz b/testdata/segment/prefix.gz new file mode 100644 index 0000000..09bccca Binary files /dev/null and b/testdata/segment/prefix.gz differ diff --git a/testdata/segment/suffix.gz b/testdata/segment/suffix.gz new file mode 100644 index 0000000..bb9ee2e Binary files /dev/null and b/testdata/segment/suffix.gz differ diff --git a/testdata/segment/want.gz b/testdata/segment/want.gz new file mode 100644 index 0000000..1aedb59 Binary files /dev/null and b/testdata/segment/want.gz differ