mirror of https://github.com/helm/helm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.2 KiB
99 lines
2.2 KiB
9 years ago
|
/*
|
||
6 years ago
|
Copyright The Helm Authors.
|
||
9 years ago
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
*/
|
||
|
|
||
6 years ago
|
package engine
|
||
9 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
8 years ago
|
"github.com/stretchr/testify/assert"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
var cases = []struct {
|
||
|
path, data string
|
||
|
}{
|
||
|
{"ship/captain.txt", "The Captain"},
|
||
|
{"ship/stowaway.txt", "Legatt"},
|
||
|
{"story/name.txt", "The Secret Sharer"},
|
||
|
{"story/author.txt", "Joseph Conrad"},
|
||
8 years ago
|
{"multiline/test.txt", "bar\nfoo"},
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
6 years ago
|
func getTestFiles() files {
|
||
|
a := make(files, len(cases))
|
||
9 years ago
|
for _, c := range cases {
|
||
7 years ago
|
a[c.path] = []byte(c.data)
|
||
9 years ago
|
}
|
||
8 years ago
|
return a
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
func TestNewFiles(t *testing.T) {
|
||
7 years ago
|
files := getTestFiles()
|
||
9 years ago
|
if len(files) != len(cases) {
|
||
|
t.Errorf("Expected len() = %d, got %d", len(cases), len(files))
|
||
|
}
|
||
|
|
||
|
for i, f := range cases {
|
||
9 years ago
|
if got := string(files.GetBytes(f.path)); got != f.data {
|
||
9 years ago
|
t.Errorf("%d: expected %q, got %q", i, f.data, got)
|
||
|
}
|
||
9 years ago
|
if got := files.Get(f.path); got != f.data {
|
||
9 years ago
|
t.Errorf("%d: expected %q, got %q", i, f.data, got)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
func TestFileGlob(t *testing.T) {
|
||
8 years ago
|
as := assert.New(t)
|
||
|
|
||
7 years ago
|
f := getTestFiles()
|
||
8 years ago
|
|
||
|
matched := f.Glob("story/**")
|
||
|
|
||
8 years ago
|
as.Len(matched, 2, "Should be two files in glob story/**")
|
||
|
as.Equal("Joseph Conrad", matched.Get("story/author.txt"))
|
||
|
}
|
||
|
|
||
|
func TestToConfig(t *testing.T) {
|
||
|
as := assert.New(t)
|
||
|
|
||
7 years ago
|
f := getTestFiles()
|
||
8 years ago
|
out := f.Glob("**/captain.txt").AsConfig()
|
||
7 years ago
|
as.Equal("captain.txt: The Captain", out)
|
||
8 years ago
|
|
||
|
out = f.Glob("ship/**").AsConfig()
|
||
7 years ago
|
as.Equal("captain.txt: The Captain\nstowaway.txt: Legatt", out)
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestToSecret(t *testing.T) {
|
||
|
as := assert.New(t)
|
||
|
|
||
7 years ago
|
f := getTestFiles()
|
||
8 years ago
|
|
||
|
out := f.Glob("ship/**").AsSecrets()
|
||
7 years ago
|
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out)
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func TestLines(t *testing.T) {
|
||
|
as := assert.New(t)
|
||
|
|
||
7 years ago
|
f := getTestFiles()
|
||
8 years ago
|
|
||
|
out := f.Lines("multiline/test.txt")
|
||
|
as.Len(out, 2)
|
||
|
|
||
|
as.Equal("bar", out[0])
|
||
|
}
|