github.com/doitroot/helm@v3.0.0-beta.3+incompatible/pkg/getter/getter_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  	"testing"
    20  
    21  	"helm.sh/helm/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  	all := All(&cli.EnvSettings{
    57  		PluginsDirectory: pluginDir,
    58  	})
    59  	if len(all) != 3 {
    60  		t.Errorf("expected 3 providers (default plus two plugins), got %d", len(all))
    61  	}
    62  
    63  	if _, err := all.ByScheme("test2"); err != nil {
    64  		t.Error(err)
    65  	}
    66  }
    67  
    68  func TestByScheme(t *testing.T) {
    69  	g := All(&cli.EnvSettings{
    70  		PluginsDirectory: pluginDir,
    71  	})
    72  	if _, err := g.ByScheme("test"); err != nil {
    73  		t.Error(err)
    74  	}
    75  	if _, err := g.ByScheme("https"); err != nil {
    76  		t.Error(err)
    77  	}
    78  }