From 9cc00eea246555e30bd06574382e60eb77233413 Mon Sep 17 00:00:00 2001 From: Zhengyi Lai Date: Sat, 24 Oct 2020 00:32:10 +0800 Subject: [PATCH] Add test case for LoadFiles Signed-off-by: Zhengyi Lai --- pkg/chart/loader/load_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/chart/loader/load_test.go b/pkg/chart/loader/load_test.go index 40b86dec2..d15753e93 100644 --- a/pkg/chart/loader/load_test.go +++ b/pkg/chart/loader/load_test.go @@ -206,6 +206,32 @@ func TestLoadFile(t *testing.T) { verifyDependencies(t, c) } +func TestLoadFiles_BadCases(t *testing.T) { + for _, tt := range []struct { + name string + bufferedFiles []*BufferedFile + expectError string + }{ + { + name: "These files contain only requirements.lock", + bufferedFiles: []*BufferedFile{ + { + Name: "requirements.lock", + Data: []byte(""), + }, + }, + expectError: "validation: chart.metadata.apiVersion is required"}, + } { + _, err := LoadFiles(tt.bufferedFiles) + if err == nil { + t.Fatal("expected error when load illegal files") + } + if !strings.Contains(err.Error(), tt.expectError) { + t.Errorf("Expected error to contain %q, got %q for %s", tt.expectError, err.Error(), tt.name) + } + } +} + func TestLoadFiles(t *testing.T) { goodFiles := []*BufferedFile{ {