github.com/rohankumardubey/draft-classic@v0.16.0/pkg/plugin/installer/local_installer_test.go (about)

     1  package installer
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/Azure/draft/pkg/draft/draftpath"
    10  )
    11  
    12  var _ Installer = new(LocalInstaller)
    13  
    14  func TestLocalInstaller(t *testing.T) {
    15  	dh, err := ioutil.TempDir("", "draft-home-")
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  	defer os.RemoveAll(dh)
    20  
    21  	home := draftpath.Home(dh)
    22  	if err := os.MkdirAll(home.Plugins(), 0755); err != nil {
    23  		t.Fatalf("Could not create %s: %s", home.Plugins(), err)
    24  	}
    25  
    26  	// Make a temp dir
    27  	tdir, err := ioutil.TempDir("", "draft-installer-")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  
    32  	defer os.RemoveAll(tdir)
    33  
    34  	if err := ioutil.WriteFile(filepath.Join(tdir, "plugin.yaml"), []byte{}, 0644); err != nil {
    35  		t.Fatal(err)
    36  	}
    37  
    38  	i, err := New(filepath.Join("..", "testdata", "plugdir", "echo"), "", home)
    39  	if err != nil {
    40  		t.Errorf("unexpected error: %s", err)
    41  	}
    42  
    43  	if err := Install(i); err != nil {
    44  		t.Error(err)
    45  	}
    46  
    47  	if i.Path() != home.Path("plugins", "echo") {
    48  		t.Errorf("expected path '$DRAFT_HOME/plugins/draft-env', got %q", i.Path())
    49  	}
    50  }