package nixbuild_test import ( "encoding/json" "slices" "strings" "testing" "git.gensokyo.uk/yonah/nixbuild" ) func TestCollectFromDerivations(t *testing.T) { testCases := []struct { name string }{ {"getchoo atlas"}, {"getchoo glados"}, {"pluiedev pappardelle"}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { var derivations nixbuild.DerivationMap if err := json.Unmarshal(drvShow[tc.name], &derivations); err != nil { t.Fatalf("cannot unmarshal test data: %v", err) } got := nixbuild.CollectFromDerivations(derivations) want := collectWant[tc.name] if !slices.Equal(got, want) { t.Errorf("CollectFromDerivations:\n%s, want\n%s", strings.Join(got, "\n"), strings.Join(want, "\n")) } }) } t.Run("edge cases", func(t *testing.T) { // this exclusively tests edge cases for nil values and buffer growing, so the data doesn't have to make sense want := []string{"", "big"} got := nixbuild.CollectFromDerivations(nixbuild.DerivationMap{ "nil": nil, "big": &nixbuild.Derivation{InputSources: make([]string, 1<<18)}, }) if !slices.Equal(got, want) { t.Errorf("CollectFromDerivations: %#v, want %#v", got, want) } }) }