From f3b205c6ef75cc3de2a0144511c4bb156570d816 Mon Sep 17 00:00:00 2001 From: Rodrigue Cloutier Date: Fri, 2 Dec 2016 08:15:36 -0500 Subject: [PATCH] fix(*): fixed tests for Windows --- .gitignore | 2 ++ cmd/helm/helmpath/helmhome_test.go | 37 -------------------- cmd/helm/helmpath/helmhome_unix_test.go | 40 ++++++++++++++++++++++ cmd/helm/helmpath/helmhome_windows_test.go | 37 ++++++++++++++++++++ cmd/helm/inspect_test.go | 6 ++-- cmd/helm/plugins_test.go | 16 ++++++--- cmd/helm/search/search.go | 6 ++-- cmd/helm/verify_test.go | 16 +++++++-- pkg/chartutil/load.go | 4 +++ pkg/tiller/release_server.go | 5 +-- 10 files changed, 118 insertions(+), 51 deletions(-) delete mode 100644 cmd/helm/helmpath/helmhome_test.go create mode 100755 cmd/helm/helmpath/helmhome_unix_test.go create mode 100755 cmd/helm/helmpath/helmhome_windows_test.go mode change 100644 => 100755 cmd/helm/inspect_test.go mode change 100644 => 100755 cmd/helm/plugins_test.go mode change 100644 => 100755 cmd/helm/search/search.go mode change 100644 => 100755 cmd/helm/verify_test.go mode change 100644 => 100755 pkg/chartutil/load.go mode change 100644 => 100755 pkg/tiller/release_server.go diff --git a/.gitignore b/.gitignore index 4613d316a..3d7644671 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ .DS_Store .coverage/ .vimrc +.vscode/ _dist/ _proto/*.pb.go bin/ rootfs/tiller vendor/ +*.exe diff --git a/cmd/helm/helmpath/helmhome_test.go b/cmd/helm/helmpath/helmhome_test.go deleted file mode 100644 index d7254f60d..000000000 --- a/cmd/helm/helmpath/helmhome_test.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package helmpath - -import ( - "testing" -) - -func TestHelmHome(t *testing.T) { - hh := Home("/r") - isEq := func(t *testing.T, a, b string) { - if a != b { - t.Errorf("Expected %q, got %q", a, b) - } - } - - isEq(t, hh.String(), "/r") - isEq(t, hh.Repository(), "/r/repository") - isEq(t, hh.RepositoryFile(), "/r/repository/repositories.yaml") - isEq(t, hh.LocalRepository(), "/r/repository/local") - isEq(t, hh.Cache(), "/r/repository/cache") - isEq(t, hh.CacheIndex("t"), "/r/repository/cache/t-index.yaml") - isEq(t, hh.Starters(), "/r/starters") -} diff --git a/cmd/helm/helmpath/helmhome_unix_test.go b/cmd/helm/helmpath/helmhome_unix_test.go new file mode 100755 index 000000000..cca303d29 --- /dev/null +++ b/cmd/helm/helmpath/helmhome_unix_test.go @@ -0,0 +1,40 @@ +// Copyright 2016 The Kubernetes Authors All rights reserved. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris +// +build !windows + +package helmpath + +import ( + "runtime" + "testing" +) + +func TestHelmHome(t *testing.T) { + hh := Home("/r") + isEq := func(t *testing.T, a, b string) { + if a != b { + t.Error(runtime.GOOS) + t.Errorf("Expected %q, got %q", a, b) + } + } + + isEq(t, hh.String(), "/r") + isEq(t, hh.Repository(), "/r/repository") + isEq(t, hh.RepositoryFile(), "/r/repository/repositories.yaml") + isEq(t, hh.LocalRepository(), "/r/repository/local") + isEq(t, hh.Cache(), "/r/repository/cache") + isEq(t, hh.CacheIndex("t"), "/r/repository/cache/t-index.yaml") + isEq(t, hh.Starters(), "/r/starters") +} diff --git a/cmd/helm/helmpath/helmhome_windows_test.go b/cmd/helm/helmpath/helmhome_windows_test.go new file mode 100755 index 000000000..11b2e9686 --- /dev/null +++ b/cmd/helm/helmpath/helmhome_windows_test.go @@ -0,0 +1,37 @@ +// Copyright 2016 The Kubernetes Authors All rights reserved. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build windows + +package helmpath + +import ( + "testing" +) + +func TestHelmHome(t *testing.T) { + hh := Home("r:\\") + isEq := func(t *testing.T, a, b string) { + if a != b { + t.Errorf("Expected %q, got %q", b, a) + } + } + + isEq(t, hh.String(), "r:\\") + isEq(t, hh.Repository(), "r:\\repository") + isEq(t, hh.RepositoryFile(), "r:\\repository\\repositories.yaml") + isEq(t, hh.LocalRepository(), "r:\\repository\\local") + isEq(t, hh.Cache(), "r:\\repository\\cache") + isEq(t, hh.CacheIndex("t"), "r:\\repository\\cache\\t-index.yaml") + isEq(t, hh.Starters(), "r:\\starters") +} diff --git a/cmd/helm/inspect_test.go b/cmd/helm/inspect_test.go old mode 100644 new mode 100755 index bbd9c6199..b34b793f6 --- a/cmd/helm/inspect_test.go +++ b/cmd/helm/inspect_test.go @@ -49,14 +49,14 @@ func TestInspect(t *testing.T) { } expect := []string{ - strings.TrimSpace(string(cdata)), - strings.TrimSpace(string(data)), + strings.Replace(strings.TrimSpace(string(cdata)), "\r", "", -1), + strings.Replace(strings.TrimSpace(string(data)), "\r", "", -1), } // Problem: ghodss/yaml doesn't marshal into struct order. To solve, we // have to carefully craft the Chart.yaml to match. for i, got := range parts { - got = strings.TrimSpace(got) + got = strings.Replace(strings.TrimSpace(got), "\r", "", -1) if got != expect[i] { t.Errorf("Expected\n%q\nGot\n%q\n", expect[i], got) } diff --git a/cmd/helm/plugins_test.go b/cmd/helm/plugins_test.go old mode 100644 new mode 100755 index 622969048..471f2370f --- a/cmd/helm/plugins_test.go +++ b/cmd/helm/plugins_test.go @@ -19,6 +19,7 @@ import ( "bytes" "os" "path/filepath" + "runtime" "strings" "testing" @@ -121,11 +122,16 @@ func TestLoadPlugins(t *testing.T) { if pp.Long != tt.long { t.Errorf("%d: Expected Use=%q, got %q", i, tt.long, pp.Long) } - if err := pp.RunE(pp, tt.args); err != nil { - t.Errorf("Error running %s: %s", tt.use, err) - } - if out.String() != tt.expect { - t.Errorf("Expected %s to output:\n%s\ngot\n%s", tt.use, tt.expect, out.String()) + + // Currently, plugins assume a Linux subsystem. Skip the execution + // tests until this is fixed + if runtime.GOOS != "windows" { + if err := pp.RunE(pp, tt.args); err != nil { + t.Errorf("Error running %s: %s", tt.use, err) + } + if out.String() != tt.expect { + t.Errorf("Expected %s to output:\n%s\ngot\n%s", tt.use, tt.expect, out.String()) + } } } } diff --git a/cmd/helm/search/search.go b/cmd/helm/search/search.go old mode 100644 new mode 100755 index bc4a8eaf1..4d394e0f5 --- a/cmd/helm/search/search.go +++ b/cmd/helm/search/search.go @@ -24,7 +24,7 @@ package search import ( "errors" - "path/filepath" + "path" "regexp" "sort" "strings" @@ -70,7 +70,9 @@ func (i *Index) AddRepo(rname string, ind *repo.IndexFile, all bool) { // By convention, an index file is supposed to have the newest at the // 0 slot, so our best bet is to grab the 0 entry and build the index // entry off of that. - fname := filepath.Join(rname, name) + // Note: Do not use filePath.Join since on Windows it will return \ + // which results in a repo name that cannot be understood. + fname := path.Join(rname, name) if !all { i.lines[fname] = indstr(rname, ref[0]) i.charts[fname] = ref[0] diff --git a/cmd/helm/verify_test.go b/cmd/helm/verify_test.go old mode 100644 new mode 100755 index 425f1a28b..fa248e67b --- a/cmd/helm/verify_test.go +++ b/cmd/helm/verify_test.go @@ -17,10 +17,22 @@ package main import ( "bytes" + "fmt" + "runtime" "testing" ) func TestVerifyCmd(t *testing.T) { + + stat_exe := "stat" + stat_path_msg := "no such file or directory" + stat_file_msg := stat_path_msg + if runtime.GOOS == "windows" { + stat_exe = "GetFileAttributesEx" + stat_path_msg = "The system cannot find the path specified." + stat_file_msg = "The system cannot find the file specified." + } + tests := []struct { name string args []string @@ -36,7 +48,7 @@ func TestVerifyCmd(t *testing.T) { { name: "verify requires that chart exists", args: []string{"no/such/file"}, - expect: "stat no/such/file: no such file or directory", + expect: fmt.Sprintf("%s no/such/file: %s", stat_exe, stat_path_msg), err: true, }, { @@ -48,7 +60,7 @@ func TestVerifyCmd(t *testing.T) { { name: "verify requires that chart has prov file", args: []string{"testdata/testcharts/compressedchart-0.1.0.tgz"}, - expect: "could not load provenance file testdata/testcharts/compressedchart-0.1.0.tgz.prov: stat testdata/testcharts/compressedchart-0.1.0.tgz.prov: no such file or directory", + expect: fmt.Sprintf("could not load provenance file testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s", stat_exe, stat_file_msg), err: true, }, { diff --git a/pkg/chartutil/load.go b/pkg/chartutil/load.go old mode 100644 new mode 100755 index 9a01bdad4..87ee8820c --- a/pkg/chartutil/load.go +++ b/pkg/chartutil/load.go @@ -229,6 +229,10 @@ func LoadDir(dir string) (*chart.Chart, error) { err = filepath.Walk(topdir, func(name string, fi os.FileInfo, err error) error { n := strings.TrimPrefix(name, topdir) + + // Normalize to / since it will also work on Windows + n = filepath.ToSlash(n) + if err != nil { return err } diff --git a/pkg/tiller/release_server.go b/pkg/tiller/release_server.go old mode 100644 new mode 100755 index abf8a30ff..35abcb15b --- a/pkg/tiller/release_server.go +++ b/pkg/tiller/release_server.go @@ -21,7 +21,7 @@ import ( "errors" "fmt" "log" - "path/filepath" + "path" "regexp" "strings" @@ -735,7 +735,8 @@ func (s *ReleaseServer) renderResources(ch *chart.Chart, values chartutil.Values for k, v := range files { if strings.HasSuffix(k, notesFileSuffix) { // Only apply the notes if it belongs to the parent chart - if k == filepath.Join(ch.Metadata.Name, "templates", notesFileSuffix) { + // Note: Do not use filePath.Join since it creates a path with \ which is not expected + if k == path.Join(ch.Metadata.Name, "templates", notesFileSuffix) { notes = v } delete(files, k)