...

Source file src/helm.sh/helm/v3/pkg/action/show_test.go

Documentation: helm.sh/helm/v3/pkg/action

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package action
    18  
    19  import (
    20  	"testing"
    21  
    22  	"helm.sh/helm/v3/pkg/chart"
    23  )
    24  
    25  func TestShow(t *testing.T) {
    26  	config := actionConfigFixture(t)
    27  	client := NewShowWithConfig(ShowAll, config)
    28  	client.chart = &chart.Chart{
    29  		Metadata: &chart.Metadata{Name: "alpine"},
    30  		Files: []*chart.File{
    31  			{Name: "README.md", Data: []byte("README\n")},
    32  			{Name: "crds/ignoreme.txt", Data: []byte("error")},
    33  			{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
    34  			{Name: "crds/bar.json", Data: []byte("---\nbar\n")},
    35  		},
    36  		Raw: []*chart.File{
    37  			{Name: "values.yaml", Data: []byte("VALUES\n")},
    38  		},
    39  		Values: map[string]interface{}{},
    40  	}
    41  
    42  	output, err := client.Run("")
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  
    47  	expect := `name: alpine
    48  
    49  ---
    50  VALUES
    51  
    52  ---
    53  README
    54  
    55  ---
    56  foo
    57  
    58  ---
    59  bar
    60  
    61  `
    62  	if output != expect {
    63  		t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
    64  	}
    65  }
    66  
    67  func TestShowNoValues(t *testing.T) {
    68  	client := NewShow(ShowAll)
    69  	client.chart = new(chart.Chart)
    70  
    71  	// Regression tests for missing values. See issue #1024.
    72  	client.OutputFormat = ShowValues
    73  	output, err := client.Run("")
    74  	if err != nil {
    75  		t.Fatal(err)
    76  	}
    77  
    78  	if len(output) != 0 {
    79  		t.Errorf("expected empty values buffer, got %s", output)
    80  	}
    81  }
    82  
    83  func TestShowValuesByJsonPathFormat(t *testing.T) {
    84  	client := NewShow(ShowValues)
    85  	client.JSONPathTemplate = "{$.nestedKey.simpleKey}"
    86  	client.chart = buildChart(withSampleValues())
    87  	output, err := client.Run("")
    88  	if err != nil {
    89  		t.Fatal(err)
    90  	}
    91  	expect := "simpleValue"
    92  	if output != expect {
    93  		t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
    94  	}
    95  }
    96  
    97  func TestShowCRDs(t *testing.T) {
    98  	client := NewShow(ShowCRDs)
    99  	client.chart = &chart.Chart{
   100  		Metadata: &chart.Metadata{Name: "alpine"},
   101  		Files: []*chart.File{
   102  			{Name: "crds/ignoreme.txt", Data: []byte("error")},
   103  			{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
   104  			{Name: "crds/bar.json", Data: []byte("---\nbar\n")},
   105  		},
   106  	}
   107  
   108  	output, err := client.Run("")
   109  	if err != nil {
   110  		t.Fatal(err)
   111  	}
   112  
   113  	expect := `---
   114  foo
   115  
   116  ---
   117  bar
   118  
   119  `
   120  	if output != expect {
   121  		t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
   122  	}
   123  }
   124  
   125  func TestShowNoReadme(t *testing.T) {
   126  	client := NewShow(ShowAll)
   127  	client.chart = &chart.Chart{
   128  		Metadata: &chart.Metadata{Name: "alpine"},
   129  		Files: []*chart.File{
   130  			{Name: "crds/ignoreme.txt", Data: []byte("error")},
   131  			{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
   132  			{Name: "crds/bar.json", Data: []byte("---\nbar\n")},
   133  		},
   134  	}
   135  
   136  	output, err := client.Run("")
   137  	if err != nil {
   138  		t.Fatal(err)
   139  	}
   140  
   141  	expect := `name: alpine
   142  
   143  ---
   144  foo
   145  
   146  ---
   147  bar
   148  
   149  `
   150  	if output != expect {
   151  		t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
   152  	}
   153  }
   154  

View as plain text