@ -17,11 +17,11 @@ limitations under the License.
package action
package action
import (
import (
"context"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"log"
"log"
"os"
"os"
"os/exec"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strings"
"strings"
@ -364,60 +364,23 @@ func TestInstallRelease_Wait(t *testing.T) {
is . Equal ( res . Info . Status , release . StatusFailed )
is . Equal ( res . Info . Status , release . StatusFailed )
}
}
func TestInstallRelease_Wait_Interrupted ( t * testing . T ) {
func TestInstallRelease_Wait_Interrupted ( t * testing . T ) {
if os . Getenv ( "HANDLE_SIGINT" ) == "1" {
is := assert . New ( t )
t . Run ( "Execute TestInstallRelease_Wait_Interrupted" , func ( t * testing . T ) {
instAction := installAction ( t )
is := assert . New ( t )
instAction . ReleaseName = "interrupted-release"
instAction := installAction ( t )
failer := instAction . cfg . KubeClient . ( * kubefake . FailingKubeClient )
instAction . ReleaseName = "interrupted-release"
failer . WaitDuration = 10 * time . Second
failer := instAction . cfg . KubeClient . ( * kubefake . FailingKubeClient )
instAction . cfg . KubeClient = failer
failer . WaitDuration = 10 * time . Second
instAction . Wait = true
instAction . cfg . KubeClient = failer
vals := map [ string ] interface { } { }
instAction . Wait = true
vals := map [ string ] interface { } { }
res , err := instAction . Run ( buildChart ( ) , vals )
is . Error ( err )
is . Contains ( res . Info . Description , "SIGTERM or SIGINT received, release failed" )
is . Equal ( res . Info . Status , release . StatusFailed )
} )
return
}
t . Run ( "Setup TestInstallRelease_Wait_Interrupted" , func ( t * testing . T ) {
cmd := exec . Command ( os . Args [ 0 ] , "-test.run=TestInstallRelease_Wait_Interrupted" )
cmd . Env = append ( os . Environ ( ) , "HANDLE_SIGINT=1" )
stdout , err := cmd . StdoutPipe ( )
if err != nil {
t . Fatal ( err )
}
stderr , err := cmd . StderrPipe ( )
if err != nil {
t . Fatal ( err )
}
if err := cmd . Start ( ) ; err != nil {
t . Fatal ( err )
}
go func ( ) {
slurp , _ := ioutil . ReadAll ( stdout )
fmt . Printf ( "%s\n" , slurp )
} ( )
go func ( ) {
slurp , _ := ioutil . ReadAll ( stderr )
fmt . Printf ( "%s\n" , slurp )
} ( )
time . Sleep ( 2 * time . Second )
p , _ := os . FindProcess ( cmd . Process . Pid )
if err := p . Signal ( os . Interrupt ) ; err != nil {
ctx := context . Background ( )
t . Fatal ( err )
ctx , cancel := context . WithCancel ( ctx )
}
time . AfterFunc ( time . Second , cancel )
if err := cmd . Wait ( ) ; err != nil {
res , err := instAction . RunWithContext ( ctx , buildChart ( ) , vals )
t . FailNow ( )
is . Error ( err )
}
is . Contains ( res . Info . Description , "Release \"interrupted-release\" failed: context canceled" )
} )
is . Equal ( res . Info . Status , release . StatusFailed )
}
}
func TestInstallRelease_WaitForJobs ( t * testing . T ) {
func TestInstallRelease_WaitForJobs ( t * testing . T ) {
is := assert . New ( t )
is := assert . New ( t )
@ -477,67 +440,31 @@ func TestInstallRelease_Atomic(t *testing.T) {
} )
} )
}
}
func TestInstallRelease_Atomic_Interrupted ( t * testing . T ) {
func TestInstallRelease_Atomic_Interrupted ( t * testing . T ) {
if os . Getenv ( "HANDLE_SIGINT" ) == "1" {
t . Run ( "Execute TestInstallRelease_Atomic_Interrupted" , func ( t * testing . T ) {
is := assert . New ( t )
instAction := installAction ( t )
instAction . ReleaseName = "interrupted-release"
failer := instAction . cfg . KubeClient . ( * kubefake . FailingKubeClient )
failer . WaitDuration = 10 * time . Second
instAction . cfg . KubeClient = failer
instAction . Atomic = true
vals := map [ string ] interface { } { }
res , err := instAction . Run ( buildChart ( ) , vals )
is . Error ( err )
is . Contains ( err . Error ( ) , "SIGTERM or SIGINT received, release failed" )
is . Contains ( err . Error ( ) , "atomic" )
is . Contains ( err . Error ( ) , "uninstalled" )
// Now make sure it isn't in storage any more
_ , err = instAction . cfg . Releases . Get ( res . Name , res . Version )
is . Error ( err )
is . Equal ( err , driver . ErrReleaseNotFound )
} )
return
}
is := assert . New ( t )
t . Run ( "Setup TestInstallRelease_Atomic_Interrupted" , func ( t * testing . T ) {
instAction := installAction ( t )
cmd := exec . Command ( os . Args [ 0 ] , "-test.run=TestInstallRelease_Atomic_Interrupted" )
instAction . ReleaseName = "interrupted-release"
cmd . Env = append ( os . Environ ( ) , "HANDLE_SIGINT=1" )
failer := instAction . cfg . KubeClient . ( * kubefake . FailingKubeClient )
stdout , err := cmd . StdoutPipe ( )
failer . WaitDuration = 10 * time . Second
if err != nil {
instAction . cfg . KubeClient = failer
t . Fatal ( err )
instAction . Atomic = true
}
vals := map [ string ] interface { } { }
stderr , err := cmd . StderrPipe ( )
if err != nil {
t . Fatal ( err )
}
if err := cmd . Start ( ) ; err != nil {
t . Fatal ( err )
}
go func ( ) {
slurp , _ := ioutil . ReadAll ( stdout )
fmt . Printf ( "%s\n" , slurp )
} ( )
go func ( ) {
ctx := context . Background ( )
slurp , _ := ioutil . ReadAll ( stderr )
ctx , cancel := context . WithCancel ( ctx )
fmt . Printf ( "%s\n" , slurp )
time . AfterFunc ( time . Second , cancel )
} ( )
time . Sleep ( 2 * time . Second )
res , err := instAction . RunWithContext ( ctx , buildChart ( ) , vals )
p , _ := os . FindProcess ( cmd . Process . Pid )
is . Error ( err )
is . Contains ( err . Error ( ) , "context canceled" )
is . Contains ( err . Error ( ) , "atomic" )
is . Contains ( err . Error ( ) , "uninstalled" )
if err := p . Signal ( os . Interrupt ) ; err != nil {
// Now make sure it isn't in storage any more
t . Fatal ( err )
_ , err = instAction . cfg . Releases . Get ( res . Name , res . Version )
}
is . Error ( err )
is . Equal ( err , driver . ErrReleaseNotFound )
if err := cmd . Wait ( ) ; err != nil {
t . FailNow ( )
}
} )
}
}
func TestNameTemplate ( t * testing . T ) {
func TestNameTemplate ( t * testing . T ) {
testCases := [ ] nameTemplateTestCase {
testCases := [ ] nameTemplateTestCase {