MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestParse

Function TestParse

pkg/tabular/tabular_test.go:33–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestParse(t *testing.T) {
34 testCases := []struct {
35 name string
36 raw []byte
37 wantErr bool
38 wantHeader []string
39 wantRows int
40 wantFirst map[string]string // subset asserted on rows[0]
41 }{
42 {
43 name: "comma csv",
44 raw: []byte("\"Path\",\"Verified\"\n\"c:\\a.dll\",\"Signed\"\n\"c:\\b.exe\",\"Unsigned\"\n"),
45 wantHeader: []string{colPath, colVerified},
46 wantRows: 2,
47 wantFirst: map[string]string{colPath: pathADLL, colVerified: "Signed"},
48 },
49 {
50 name: "tab separated",
51 raw: []byte("Path\tVerified\tCompany\nc:\\a.dll\tSigned\tMicrosoft\n"),
52 wantHeader: []string{colPath, colVerified, "Company"},
53 wantRows: 1,
54 wantFirst: map[string]string{colPath: pathADLL, "Company": "Microsoft"},
55 },
56 {
57 name: "utf-8 BOM stripped",
58 raw: append([]byte{0xEF, 0xBB, 0xBF}, []byte("Path,Verified\nc:\\a.dll,Signed\n")...),
59 wantHeader: []string{colPath, colVerified},
60 wantRows: 1,
61 wantFirst: map[string]string{colPath: pathADLL},
62 },
63 {
64 name: "utf-16 LE BOM decoded",
65 raw: utf16LE("Path,Verified\nc:\\a.dll,Signed\n"),
66 wantHeader: []string{colPath, colVerified},
67 wantRows: 1,
68 wantFirst: map[string]string{colPath: pathADLL},
69 },
70 {
71 name: "utf-16 BE BOM decoded",
72 raw: utf16BE("Path,Verified\nc:\\a.dll,Signed\n"),
73 wantHeader: []string{colPath, colVerified},
74 wantRows: 1,
75 wantFirst: map[string]string{colPath: pathADLL},
76 },
77 {
78 name: "header only is a clean scan",
79 raw: []byte("Path,Verified\n"),
80 wantHeader: []string{colPath, colVerified},
81 wantRows: 0,
82 },
83 {
84 name: "empty input",
85 raw: []byte(" \n"),
86 wantErr: true,
87 },
88 }
89
90 for _, tc := range testCases {

Callers

nothing calls this directly

Calls 5

ParseFunction · 0.92
utf16LEFunction · 0.85
utf16BEFunction · 0.85
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected