MCPcopy
hub / github.com/helm/helm / createChartArchive

Function createChartArchive

pkg/chart/loader/load_test.go:37–77  ·  view source on GitHub ↗

createChartArchive is a helper function to create a gzipped tar archive in memory

(t *testing.T, chartName, apiVersion string, extraFiles map[string][]byte, createChartYaml bool)

Source from the content-addressed store, hash-verified

35
36// createChartArchive is a helper function to create a gzipped tar archive in memory
37func createChartArchive(t *testing.T, chartName, apiVersion string, extraFiles map[string][]byte, createChartYaml bool) io.Reader {
38 t.Helper()
39 var buf bytes.Buffer
40 gw := gzip.NewWriter(&buf)
41 tw := tar.NewWriter(gw)
42
43 files := make(map[string][]byte)
44 maps.Copy(files, extraFiles)
45
46 if createChartYaml {
47 chartYAMLContent := fmt.Sprintf(`apiVersion: %s
48name: %s
49version: 0.1.0
50description: A test chart
51`, apiVersion, chartName)
52 files["Chart.yaml"] = []byte(chartYAMLContent)
53 }
54
55 for name, data := range files {
56 header := &tar.Header{
57 Name: filepath.Join(chartName, name),
58 Mode: 0644,
59 Size: int64(len(data)),
60 ModTime: time.Now(),
61 }
62 if err := tw.WriteHeader(header); err != nil {
63 t.Fatalf("Failed to write tar header for %s: %v", name, err)
64 }
65 if _, err := tw.Write(data); err != nil {
66 t.Fatalf("Failed to write tar data for %s: %v", name, err)
67 }
68 }
69
70 if err := tw.Close(); err != nil {
71 t.Fatalf("Failed to close tar writer: %v", err)
72 }
73 if err := gw.Close(); err != nil {
74 t.Fatalf("Failed to close gzip writer: %v", err)
75 }
76 return &buf
77}
78
79func TestLoadArchive(t *testing.T) {
80 testCases := []struct {

Callers 1

TestLoadArchiveFunction · 0.85

Calls 6

HelperMethod · 0.80
CopyMethod · 0.80
NowMethod · 0.80
FatalfMethod · 0.80
CloseMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…