--- 4. streamJSONLFile ---
(t *testing.T)
| 107 | // --- 4. streamJSONLFile --- |
| 108 | |
| 109 | func TestStreamJSONLFile(t *testing.T) { |
| 110 | dir := t.TempDir() |
| 111 | path := filepath.Join(dir, "test.jsonl") |
| 112 | |
| 113 | entries := []db.DLLMatch{ |
| 114 | {DLLName: "foo.dll", Source: "nuget", PackageName: "FooPkg", Version: "1.0.0", Hash: "abc123"}, |
| 115 | {DLLName: "bar.dll", Source: "nuget", PackageName: "BarPkg", Version: "2.0.0"}, |
| 116 | } |
| 117 | |
| 118 | f, err := os.Create(path) |
| 119 | if err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | enc := json.NewEncoder(f) |
| 123 | for _, e := range entries { |
| 124 | enc.Encode(e) |
| 125 | } |
| 126 | f.Close() |
| 127 | |
| 128 | var got []db.DLLMatch |
| 129 | err = streamJSONLFile(path, func(e db.DLLMatch) { |
| 130 | got = append(got, e) |
| 131 | }) |
| 132 | if err != nil { |
| 133 | t.Fatal(err) |
| 134 | } |
| 135 | if len(got) != 2 { |
| 136 | t.Fatalf("got %d entries, want 2", len(got)) |
| 137 | } |
| 138 | if got[0].DLLName != "foo.dll" { |
| 139 | t.Errorf("entry[0].DLLName = %q, want %q", got[0].DLLName, "foo.dll") |
| 140 | } |
| 141 | if got[0].Hash != "abc123" { |
| 142 | t.Errorf("entry[0].Hash = %q, want %q", got[0].Hash, "abc123") |
| 143 | } |
| 144 | if got[1].PackageName != "BarPkg" { |
| 145 | t.Errorf("entry[1].PackageName = %q, want %q", got[1].PackageName, "BarPkg") |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | func TestStreamJSONLFileNotFound(t *testing.T) { |
| 150 | err := streamJSONLFile("/nonexistent/file.jsonl", func(e db.DLLMatch) {}) |
nothing calls this directly
no test coverage detected