...

Source file src/helm.sh/helm/v3/pkg/getter/getter_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  	"testing"
    20  
    21  	"helm.sh/helm/v3/pkg/cli"
    22  )
    23  
    24  const pluginDir = "testdata/plugins"
    25  
    26  func TestProvider(t *testing.T) {
    27  	p := Provider{
    28  		[]string{"one", "three"},
    29  		func(_ ...Option) (Getter, error) { return nil, nil },
    30  	}
    31  
    32  	if !p.Provides("three") {
    33  		t.Error("Expected provider to provide three")
    34  	}
    35  }
    36  
    37  func TestProviders(t *testing.T) {
    38  	ps := Providers{
    39  		{[]string{"one", "three"}, func(_ ...Option) (Getter, error) { return nil, nil }},
    40  		{[]string{"two", "four"}, func(_ ...Option) (Getter, error) { return nil, nil }},
    41  	}
    42  
    43  	if _, err := ps.ByScheme("one"); err != nil {
    44  		t.Error(err)
    45  	}
    46  	if _, err := ps.ByScheme("four"); err != nil {
    47  		t.Error(err)
    48  	}
    49  
    50  	if _, err := ps.ByScheme("five"); err == nil {
    51  		t.Error("Did not expect handler for five")
    52  	}
    53  }
    54  
    55  func TestAll(t *testing.T) {
    56  	env := cli.New()
    57  	env.PluginsDirectory = pluginDir
    58  
    59  	all := All(env)
    60  	if len(all) != 4 {
    61  		t.Errorf("expected 4 providers (default plus three plugins), got %d", len(all))
    62  	}
    63  
    64  	if _, err := all.ByScheme("test2"); err != nil {
    65  		t.Error(err)
    66  	}
    67  }
    68  
    69  func TestByScheme(t *testing.T) {
    70  	env := cli.New()
    71  	env.PluginsDirectory = pluginDir
    72  
    73  	g := All(env)
    74  	if _, err := g.ByScheme("test"); err != nil {
    75  		t.Error(err)
    76  	}
    77  	if _, err := g.ByScheme("https"); err != nil {
    78  		t.Error(err)
    79  	}
    80  }
    81  

View as plain text