github.com/migueleliasweb/helm@v2.6.1+incompatible/pkg/getter/plugingetter_test.go (about)

     1  /*
     2  Copyright 2017 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 getter
    17  
    18  import (
    19  	"os"
    20  	"path/filepath"
    21  	"strings"
    22  	"testing"
    23  
    24  	"k8s.io/helm/pkg/helm/environment"
    25  	"k8s.io/helm/pkg/helm/helmpath"
    26  )
    27  
    28  func hh(debug bool) environment.EnvSettings {
    29  	apath, err := filepath.Abs("./testdata")
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  	hp := helmpath.Home(apath)
    34  	return environment.EnvSettings{
    35  		Home:  hp,
    36  		Debug: debug,
    37  	}
    38  }
    39  
    40  func TestCollectPlugins(t *testing.T) {
    41  	// Reset HELM HOME to testdata.
    42  	oldhh := os.Getenv("HELM_HOME")
    43  	defer os.Setenv("HELM_HOME", oldhh)
    44  	os.Setenv("HELM_HOME", "")
    45  
    46  	env := hh(false)
    47  	p, err := collectPlugins(env)
    48  	if err != nil {
    49  		t.Fatal(err)
    50  	}
    51  
    52  	if len(p) != 2 {
    53  		t.Errorf("Expected 2 plugins, got %d: %v", len(p), p)
    54  	}
    55  
    56  	if _, err := p.ByScheme("test2"); err != nil {
    57  		t.Error(err)
    58  	}
    59  
    60  	if _, err := p.ByScheme("test"); err != nil {
    61  		t.Error(err)
    62  	}
    63  
    64  	if _, err := p.ByScheme("nosuchthing"); err == nil {
    65  		t.Fatal("did not expect protocol handler for nosuchthing")
    66  	}
    67  }
    68  
    69  func TestPluginGetter(t *testing.T) {
    70  	oldhh := os.Getenv("HELM_HOME")
    71  	defer os.Setenv("HELM_HOME", oldhh)
    72  	os.Setenv("HELM_HOME", "")
    73  
    74  	env := hh(false)
    75  	pg := newPluginGetter("echo", env, "test", ".")
    76  	g, err := pg("test://foo/bar", "", "", "")
    77  	if err != nil {
    78  		t.Fatal(err)
    79  	}
    80  
    81  	data, err := g.Get("test://foo/bar")
    82  	if err != nil {
    83  		t.Fatal(err)
    84  	}
    85  
    86  	expect := "test://foo/bar"
    87  	got := strings.TrimSpace(data.String())
    88  	if got != expect {
    89  		t.Errorf("Expected %q, got %q", expect, got)
    90  	}
    91  }