...

Source file src/helm.sh/helm/v3/pkg/plugin/installer/local_installer_test.go

Documentation: helm.sh/helm/v3/pkg/plugin/installer

     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 installer // import "helm.sh/helm/v3/pkg/plugin/installer"
    17  
    18  import (
    19  	"os"
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	"helm.sh/helm/v3/pkg/helmpath"
    24  )
    25  
    26  var _ Installer = new(LocalInstaller)
    27  
    28  func TestLocalInstaller(t *testing.T) {
    29  	// Make a temp dir
    30  	tdir := t.TempDir()
    31  	if err := os.WriteFile(filepath.Join(tdir, "plugin.yaml"), []byte{}, 0644); err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	source := "../testdata/plugdir/good/echo"
    36  	i, err := NewForSource(source, "")
    37  	if err != nil {
    38  		t.Fatalf("unexpected error: %s", err)
    39  	}
    40  
    41  	if err := Install(i); err != nil {
    42  		t.Fatal(err)
    43  	}
    44  
    45  	if i.Path() != helmpath.DataPath("plugins", "echo") {
    46  		t.Fatalf("expected path '$XDG_CONFIG_HOME/helm/plugins/helm-env', got %q", i.Path())
    47  	}
    48  	defer os.RemoveAll(filepath.Dir(helmpath.DataPath())) // helmpath.DataPath is like /tmp/helm013130971/helm
    49  }
    50  
    51  func TestLocalInstallerNotAFolder(t *testing.T) {
    52  	source := "../testdata/plugdir/good/echo/plugin.yaml"
    53  	i, err := NewForSource(source, "")
    54  	if err != nil {
    55  		t.Fatalf("unexpected error: %s", err)
    56  	}
    57  
    58  	err = Install(i)
    59  	if err == nil {
    60  		t.Fatal("expected error")
    61  	}
    62  	if err != ErrPluginNotAFolder {
    63  		t.Fatalf("expected error to equal: %q", err)
    64  	}
    65  }
    66  

View as plain text