@ -48,6 +48,7 @@ func (r *testRepo) UpdateVersion(version string) error {
r . current = version
return r . err
}
func ( r * testRepo ) IsDirty ( ) bool { return false }
func TestVCSInstaller ( t * testing . T ) {
ensure . HelmHome ( t )
@ -96,7 +97,7 @@ func TestVCSInstaller(t *testing.T) {
}
// Testing FindSource method, expect error because plugin code is not a cloned repository
if _ , err := FindSource ( i . Path ( ) ); err == nil {
if _ , err := FindSource ( i . Path ( ) , "" ); err == nil {
t . Fatalf ( "expected error for inability to find plugin source, got none" )
} else if err . Error ( ) != "cannot get information about plugin source" {
t . Fatalf ( "expected error for inability to find plugin source, got (%v)" , err )
@ -158,7 +159,7 @@ func TestVCSInstallerUpdate(t *testing.T) {
}
// Test FindSource method for positive result
pluginInfo , err := FindSource ( i . Path ( ) )
pluginInfo , err := FindSource ( i . Path ( ) , "" )
if err != nil {
t . Fatal ( err )
}
@ -187,3 +188,61 @@ func TestVCSInstallerUpdate(t *testing.T) {
}
}
func TestVCSInstallerUpdateWithVersion ( t * testing . T ) {
ensure . HelmHome ( t )
if err := os . MkdirAll ( helmpath . DataPath ( "plugins" ) , 0755 ) ; err != nil {
t . Fatalf ( "Could not create %s: %s" , helmpath . DataPath ( "plugins" ) , err )
}
source := "https://github.com/adamreese/helm-env"
testRepoPath , _ := filepath . Abs ( "../testdata/plugdir/good/echo-v1" )
repo := & testRepo {
local : testRepoPath ,
remote : source ,
tags : [ ] string { "0.1.0" , "0.1.1" , "0.2.0" } ,
}
// First install without version
i , err := NewForSource ( source , "" )
if err != nil {
t . Fatalf ( "unexpected error: %s" , err )
}
vcsInstaller , ok := i . ( * VCSInstaller )
if ! ok {
t . Fatal ( "expected a VCSInstaller" )
}
vcsInstaller . Repo = repo
if err := Install ( i ) ; err != nil {
t . Fatal ( err )
}
// Now test update with specific version constraint
vcsInstaller . Version = "~0.1.0"
if err := Update ( vcsInstaller ) ; err != nil {
t . Fatal ( err )
}
if repo . current != "0.1.1" {
t . Fatalf ( "expected version '0.1.1', got %q" , repo . current )
}
// Test update with different version constraint
vcsInstaller . Version = "0.2.0"
if err := Update ( vcsInstaller ) ; err != nil {
t . Fatal ( err )
}
if repo . current != "0.2.0" {
t . Fatalf ( "expected version '0.2.0', got %q" , repo . current )
}
// Test update with non-existent version
vcsInstaller . Version = "0.3.0"
if err := Update ( vcsInstaller ) ; err == nil {
t . Fatal ( "expected error for version does not exist, got none" )
} else if err . Error ( ) != fmt . Sprintf ( "requested version %q does not exist for plugin %q" , "0.3.0" , source ) {
t . Fatalf ( "expected error for version does not exist, got (%v)" , err )
}
}