github.com/uhthomas/helm@v3.0.0-beta.3+incompatible/pkg/action/show_test.go (about)

     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  	"io/ioutil"
    21  	"strings"
    22  	"testing"
    23  )
    24  
    25  func TestShow(t *testing.T) {
    26  	client := NewShow(ShowAll)
    27  
    28  	output, err := client.Run("../../cmd/helm/testdata/testcharts/alpine")
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  
    33  	// Load the data from the textfixture directly.
    34  	cdata, err := ioutil.ReadFile("../../cmd/helm/testdata/testcharts/alpine/Chart.yaml")
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	data, err := ioutil.ReadFile("../../cmd/helm/testdata/testcharts/alpine/values.yaml")
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	readmeData, err := ioutil.ReadFile("../../cmd/helm/testdata/testcharts/alpine/README.md")
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  	parts := strings.SplitN(output, "---", 3)
    47  	if len(parts) != 3 {
    48  		t.Fatalf("Expected 2 parts, got %d", len(parts))
    49  	}
    50  
    51  	expect := []string{
    52  		strings.ReplaceAll(strings.TrimSpace(string(cdata)), "\r", ""),
    53  		strings.ReplaceAll(strings.TrimSpace(string(data)), "\r", ""),
    54  		strings.ReplaceAll(strings.TrimSpace(string(readmeData)), "\r", ""),
    55  	}
    56  
    57  	// Problem: ghodss/yaml doesn't marshal into struct order. To solve, we
    58  	// have to carefully craft the Chart.yaml to match.
    59  	for i, got := range parts {
    60  		got = strings.ReplaceAll(strings.TrimSpace(got), "\r", "")
    61  		if got != expect[i] {
    62  			t.Errorf("Expected\n%q\nGot\n%q\n", expect[i], got)
    63  		}
    64  	}
    65  
    66  	// Regression tests for missing values. See issue #1024.
    67  	client.OutputFormat = ShowValues
    68  	output, err = client.Run("../../cmd/helm/testdata/testcharts/novals")
    69  	if err != nil {
    70  		t.Fatal(err)
    71  	}
    72  
    73  	if len(output) != 0 {
    74  		t.Errorf("expected empty values buffer, got %s", output)
    75  	}
    76  }