From 476200ed061fff0030c4c3f2918a581735b731eb Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Fri, 3 Jan 2020 18:05:23 +0800 Subject: [PATCH] Add corresponding unit test to the function in resolver.go Signed-off-by: Guangwen Feng --- internal/resolver/resolver_test.go | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/internal/resolver/resolver_test.go b/internal/resolver/resolver_test.go index 3828771cc..d93d616ee 100644 --- a/internal/resolver/resolver_test.go +++ b/internal/resolver/resolver_test.go @@ -216,3 +216,61 @@ func TestHashReq(t *testing.T) { }) } } + +func TestGetLocalPath(t *testing.T) { + tests := []struct { + name string + repo string + chartpath string + expect string + err bool + }{ + { + name: "absolute path", + repo: "file:////proc", + expect: "/proc", + }, + { + name: "relative path", + repo: "file://../../../../cmd/helm/testdata/testcharts/signtest", + chartpath: "foo/bar", + expect: "../../cmd/helm/testdata/testcharts/signtest", + }, + { + name: "current directory path", + repo: "../charts/localdependency", + chartpath: "testdata/chartpath/charts", + expect: "testdata/chartpath/charts/localdependency", + }, + { + name: "invalid local path", + repo: "file://../testdata/notexist", + chartpath: "testdata/chartpath", + err: true, + }, + { + name: "invalid path under current directory", + repo: "../charts/nonexistentdependency", + chartpath: "testdata/chartpath/charts", + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p, err := GetLocalPath(tt.repo, tt.chartpath) + if err != nil { + if tt.err { + return + } + t.Fatal(err) + } + if tt.err { + t.Fatalf("Expected error in test %q", tt.name) + } + if p != tt.expect { + t.Errorf("%q: expected %q, got %q", tt.name, tt.expect, p) + } + }) + } +}