github.com/danielqsj/helm@v2.0.0-alpha.4.0.20160908204436-976e0ba5199b+incompatible/pkg/chartutil/files_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package chartutil
    17  
    18  import (
    19  	"testing"
    20  
    21  	"github.com/golang/protobuf/ptypes/any"
    22  )
    23  
    24  func TestNewFiles(t *testing.T) {
    25  
    26  	cases := []struct {
    27  		path, data string
    28  	}{
    29  		{"ship/captain.txt", "The Captain"},
    30  		{"ship/stowaway.txt", "Legatt"},
    31  		{"story/name.txt", "The Secret Sharer"},
    32  		{"story/author.txt", "Joseph Conrad"},
    33  	}
    34  
    35  	a := []*any.Any{}
    36  	for _, c := range cases {
    37  		a = append(a, &any.Any{TypeUrl: c.path, Value: []byte(c.data)})
    38  	}
    39  
    40  	files := NewFiles(a)
    41  	if len(files) != len(cases) {
    42  		t.Errorf("Expected len() = %d, got %d", len(cases), len(files))
    43  	}
    44  
    45  	for i, f := range cases {
    46  		if got := string(files.GetBytes(f.path)); got != f.data {
    47  			t.Errorf("%d: expected %q, got %q", i, f.data, got)
    48  		}
    49  		if got := files.Get(f.path); got != f.data {
    50  			t.Errorf("%d: expected %q, got %q", i, f.data, got)
    51  		}
    52  	}
    53  }