...

Source file src/helm.sh/helm/v3/pkg/getter/plugingetter_test.go

Documentation: helm.sh/helm/v3/pkg/getter

     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/v3/pkg/cli"
    24  )
    25  
    26  func TestCollectPlugins(t *testing.T) {
    27  	env := cli.New()
    28  	env.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.New()
    58  	env.PluginsDirectory = pluginDir
    59  	pg := NewPluginGetter("echo", env, "test", ".")
    60  	g, err := pg()
    61  	if err != nil {
    62  		t.Fatal(err)
    63  	}
    64  
    65  	data, err := g.Get("test://foo/bar")
    66  	if err != nil {
    67  		t.Fatal(err)
    68  	}
    69  
    70  	expect := "test://foo/bar"
    71  	got := strings.TrimSpace(data.String())
    72  	if got != expect {
    73  		t.Errorf("Expected %q, got %q", expect, got)
    74  	}
    75  }
    76  
    77  func TestPluginSubCommands(t *testing.T) {
    78  	if runtime.GOOS == "windows" {
    79  		t.Skip("TODO: refactor this test to work on windows")
    80  	}
    81  
    82  	env := cli.New()
    83  	env.PluginsDirectory = pluginDir
    84  
    85  	pg := NewPluginGetter("echo -n", env, "test", ".")
    86  	g, err := pg()
    87  	if err != nil {
    88  		t.Fatal(err)
    89  	}
    90  
    91  	data, err := g.Get("test://foo/bar")
    92  	if err != nil {
    93  		t.Fatal(err)
    94  	}
    95  
    96  	expect := "   test://foo/bar"
    97  	got := data.String()
    98  	if got != expect {
    99  		t.Errorf("Expected %q, got %q", expect, got)
   100  	}
   101  }
   102  

View as plain text