github.com/diafour/helm@v3.0.0-beta.3+incompatible/pkg/getter/plugingetter_test.go (about)

     1  /*
     2  Copyright The Helm Authors.
     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  	"runtime"
    20  	"strings"
    21  	"testing"
    22  
    23  	"helm.sh/helm/pkg/cli"
    24  )
    25  
    26  func TestCollectPlugins(t *testing.T) {
    27  	env := &cli.EnvSettings{
    28  		PluginsDirectory: pluginDir,
    29  	}
    30  	p, err := collectPlugins(env)
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	if len(p) != 2 {
    36  		t.Errorf("Expected 2 plugins, got %d: %v", len(p), p)
    37  	}
    38  
    39  	if _, err := p.ByScheme("test2"); err != nil {
    40  		t.Error(err)
    41  	}
    42  
    43  	if _, err := p.ByScheme("test"); err != nil {
    44  		t.Error(err)
    45  	}
    46  
    47  	if _, err := p.ByScheme("nosuchthing"); err == nil {
    48  		t.Fatal("did not expect protocol handler for nosuchthing")
    49  	}
    50  }
    51  
    52  func TestPluginGetter(t *testing.T) {
    53  	if runtime.GOOS == "windows" {
    54  		t.Skip("TODO: refactor this test to work on windows")
    55  	}
    56  
    57  	env := &cli.EnvSettings{
    58  		PluginsDirectory: pluginDir,
    59  	}
    60  	pg := NewPluginGetter("echo", env, "test", ".")
    61  	g, err := pg()
    62  	if err != nil {
    63  		t.Fatal(err)
    64  	}
    65  
    66  	data, err := g.Get("test://foo/bar")
    67  	if err != nil {
    68  		t.Fatal(err)
    69  	}
    70  
    71  	expect := "test://foo/bar"
    72  	got := strings.TrimSpace(data.String())
    73  	if got != expect {
    74  		t.Errorf("Expected %q, got %q", expect, got)
    75  	}
    76  }
    77  
    78  func TestPluginSubCommands(t *testing.T) {
    79  	if runtime.GOOS == "windows" {
    80  		t.Skip("TODO: refactor this test to work on windows")
    81  	}
    82  
    83  	env := &cli.EnvSettings{
    84  		PluginsDirectory: pluginDir,
    85  	}
    86  	pg := NewPluginGetter("echo -n", env, "test", ".")
    87  	g, err := pg()
    88  	if err != nil {
    89  		t.Fatal(err)
    90  	}
    91  
    92  	data, err := g.Get("test://foo/bar")
    93  	if err != nil {
    94  		t.Fatal(err)
    95  	}
    96  
    97  	expect := "   test://foo/bar"
    98  	got := data.String()
    99  	if got != expect {
   100  		t.Errorf("Expected %q, got %q", expect, got)
   101  	}
   102  }