From 180bc7da05b8fa06c38c678e3bb2021a1d4c2d94 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 28 Jan 2016 12:21:56 -0700 Subject: [PATCH] Load chartfile into chart on chart file load. Best commit message ever. --- chart/chart.go | 19 +++++++++++++++++-- chart/chart_test.go | 18 ++++++++++++++---- chart/chartfile_test.go | 4 ++-- chart/testdata/nochart.tgz | Bin 0 -> 325 bytes 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 chart/testdata/nochart.tgz diff --git a/chart/chart.go b/chart/chart.go index 514a4001b..2f0a35c42 100644 --- a/chart/chart.go +++ b/chart/chart.go @@ -14,6 +14,8 @@ import ( "github.com/kubernetes/deployment-manager/log" ) +const ChartfileName string = "Chart.yaml" + const ( preTemplates string = "templates/" preHooks string = "hooks/" @@ -42,11 +44,13 @@ type Chart interface { // Dir returns a directory where the chart can be accessed. Dir() string + // Close cleans up a chart. Close() error } type dirChart struct { chartfile *Chartfile + dir string } func (d *dirChart) Chartfile() *Chartfile { @@ -99,6 +103,7 @@ func LoadDir(chart string) (Chart, error) { c := &dirChart{ chartfile: cf, + dir: chart, } return c, nil @@ -128,10 +133,20 @@ func Load(archive string) (Chart, error) { defer unzipped.Close() untarred := tar.NewReader(unzipped) - return loadTar(untarred) + c, err := loadTar(untarred) + if err != nil { + return c, err + } + + cf, err := LoadChartfile(filepath.Join(c.tmpDir, ChartfileName)) + if err != nil { + return c, err + } + c.chartfile = cf + return c, nil } -func loadTar(r *tar.Reader) (Chart, error) { +func loadTar(r *tar.Reader) (*tarChart, error) { td, err := ioutil.TempDir("", "chart-") if err != nil { return nil, err diff --git a/chart/chart_test.go b/chart/chart_test.go index 91f020f3e..5a16dc6bf 100644 --- a/chart/chart_test.go +++ b/chart/chart_test.go @@ -6,10 +6,13 @@ import ( "github.com/kubernetes/deployment-manager/log" ) -const testfile = "testdata/frobnitz/Chart.yaml" -const testdir = "testdata/frobnitz/" -const testarchive = "testdata/frobnitz-0.0.1.tgz" -const testill = "testdata/ill-1.2.3.tgz" +const ( + testfile = "testdata/frobnitz/Chart.yaml" + testdir = "testdata/frobnitz/" + testarchive = "testdata/frobnitz-0.0.1.tgz" + testill = "testdata/ill-1.2.3.tgz" + testnochart = "testdata/nochart.tgz" +) func init() { log.IsDebugging = true @@ -62,3 +65,10 @@ func TestLoadIll(t *testing.T) { return } } + +func TestLoadNochart(t *testing.T) { + _, err := Load(testnochart) + if err == nil { + t.Error("Nochart should not have loaded at all.") + } +} diff --git a/chart/chartfile_test.go b/chart/chartfile_test.go index 92781d3fa..d1d21d3f3 100644 --- a/chart/chartfile_test.go +++ b/chart/chartfile_test.go @@ -31,8 +31,8 @@ func TestLoadChartfile(t *testing.T) { t.Errorf("Expected second dependency to be thingerbob: %q", f.Dependencies[0].Name) } - if f.Source[0] != "https://example.com/helm" { - t.Errorf("Expected https://example.com/helm, got %s", f.Source) + if f.Source[0] != "https://example.com/foo/bar" { + t.Errorf("Expected https://example.com/foo/bar, got %s", f.Source) } } diff --git a/chart/testdata/nochart.tgz b/chart/testdata/nochart.tgz new file mode 100644 index 0000000000000000000000000000000000000000..f5a235537aa99fd1b58faec20e3e3e871f5b2ab1 GIT binary patch literal 325 zcmV-L0lNMliwFP@XsT8K1MSj5PlGTR2H>6f72n01Vqt@wm$;)B;}4*eVw*s_wBI!D z*V{2&h*58gF}}~Glze%43p{K$clX=u_Jgs4|5IWZ+0_BvX1x%A`w8ai^8-t&(iL%d_m5)AYfQ&hp{5nMEn@SXviJo}y++ zI!;;B?d-e6_Lz7ha*-D~KOGwC?V!n~JV!DpW1ltoehNB|&z}F0WQU=7FCbkv>t{bT zOMB;;3L&mi_i>l{w1d9R($7IJ#-{T}