github.com/wangchanggan/helm@v0.0.0-20211020154240-11b1b7d5406d/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 "os" 20 "testing" 21 ) 22 23 func TestProvider(t *testing.T) { 24 p := Provider{ 25 []string{"one", "three"}, 26 func(h, e, l, m string) (Getter, error) { return nil, nil }, 27 } 28 29 if !p.Provides("three") { 30 t.Error("Expected provider to provide three") 31 } 32 } 33 34 func TestProviders(t *testing.T) { 35 ps := Providers{ 36 {[]string{"one", "three"}, func(h, e, l, m string) (Getter, error) { return nil, nil }}, 37 {[]string{"two", "four"}, func(h, e, l, m string) (Getter, error) { return nil, nil }}, 38 } 39 40 if _, err := ps.ByScheme("one"); err != nil { 41 t.Error(err) 42 } 43 if _, err := ps.ByScheme("four"); err != nil { 44 t.Error(err) 45 } 46 47 if _, err := ps.ByScheme("five"); err == nil { 48 t.Error("Did not expect handler for five") 49 } 50 } 51 52 func TestAll(t *testing.T) { 53 oldhh := os.Getenv("HELM_HOME") 54 defer os.Setenv("HELM_HOME", oldhh) 55 os.Setenv("HELM_HOME", "") 56 57 env := hh(false) 58 59 all := All(env) 60 if len(all) != 3 { 61 t.Errorf("expected 3 providers (default plus two 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 oldhh := os.Getenv("HELM_HOME") 71 defer os.Setenv("HELM_HOME", oldhh) 72 os.Setenv("HELM_HOME", "") 73 74 env := hh(false) 75 if _, err := ByScheme("test", env); err != nil { 76 t.Error(err) 77 } 78 if _, err := ByScheme("https", env); err != nil { 79 t.Error(err) 80 } 81 }