MCPcopy
hub / github.com/helm/helm / TestBomTestData

Function TestBomTestData

pkg/chart/v2/loader/load_test.go:93–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestBomTestData(t *testing.T) {
94 testFiles := []string{"frobnitz_with_bom/.helmignore", "frobnitz_with_bom/templates/template.tpl", "frobnitz_with_bom/Chart.yaml"}
95 for _, file := range testFiles {
96 data, err := os.ReadFile("testdata/" + file)
97 if err != nil || !bytes.HasPrefix(data, utf8bom) {
98 t.Errorf("Test file has no BOM or is invalid: testdata/%s", file)
99 }
100 }
101
102 archive, err := os.ReadFile("testdata/frobnitz_with_bom.tgz")
103 if err != nil {
104 t.Fatalf("Error reading archive frobnitz_with_bom.tgz: %s", err)
105 }
106 unzipped, err := gzip.NewReader(bytes.NewReader(archive))
107 if err != nil {
108 t.Fatalf("Error reading archive frobnitz_with_bom.tgz: %s", err)
109 }
110 defer unzipped.Close()
111 for _, testFile := range testFiles {
112 data := make([]byte, 3)
113 err := unzipped.Reset(bytes.NewReader(archive))
114 if err != nil {
115 t.Fatalf("Error reading archive frobnitz_with_bom.tgz: %s", err)
116 }
117 tr := tar.NewReader(unzipped)
118 for {
119 file, err := tr.Next()
120 if errors.Is(err, io.EOF) {
121 break
122 }
123 if err != nil {
124 t.Fatalf("Error reading archive frobnitz_with_bom.tgz: %s", err)
125 }
126 if file != nil && strings.EqualFold(file.Name, testFile) {
127 _, err := tr.Read(data)
128 if err != nil {
129 t.Fatalf("Error reading archive frobnitz_with_bom.tgz: %s", err)
130 } else {
131 break
132 }
133 }
134 }
135 if !bytes.Equal(data, utf8bom) {
136 t.Fatalf("Test file has no BOM or is invalid: frobnitz_with_bom.tgz/%s", testFile)
137 }
138 }
139}
140
141func TestLoadDirWithUTFBOM(t *testing.T) {
142 l, err := Loader("testdata/frobnitz_with_bom")

Callers

nothing calls this directly

Calls 4

FatalfMethod · 0.80
CloseMethod · 0.80
IsMethod · 0.80
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…