@ -39,12 +39,20 @@ import (
helmtime "helm.sh/helm/v3/pkg/time"
)
const ExternalFileRelPath = "testdata/files/external.txt"
type nameTemplateTestCase struct {
tpl string
expected string
expectedErrorStr string
}
type includeExternalPathTestCase struct {
Name string
IncludedFilePath string
ExternalPath string
}
func installAction ( t * testing . T ) * Install {
config := actionConfigFixture ( t )
instAction := NewInstall ( config )
@ -54,6 +62,11 @@ func installAction(t *testing.T) *Install {
return instAction
}
func getAbsPath ( path string ) string {
absPath , _ := filepath . Abs ( path )
return absPath
}
func TestInstallRelease ( t * testing . T ) {
is := assert . New ( t )
req := require . New ( t )
@ -717,3 +730,86 @@ func TestNameAndChartGenerateName(t *testing.T) {
} )
}
}
func TestInstallFailsWhenWrongPathsIncluded ( t * testing . T ) {
is := assert . New ( t )
vals := map [ string ] interface { } { }
tests := [ ] includeExternalPathTestCase {
{
Name : "included paths not passed" ,
IncludedFilePath : "" ,
ExternalPath : ExternalFileRelPath ,
} ,
{
Name : "absolute path of file is included and external file is relative" ,
IncludedFilePath : getAbsPath ( ExternalFileRelPath ) ,
ExternalPath : ExternalFileRelPath ,
} ,
{
Name : "relative path of file is included and external file is absolute" ,
IncludedFilePath : ExternalFileRelPath ,
ExternalPath : getAbsPath ( ExternalFileRelPath ) ,
} ,
{
Name : "absolute path of directory is included and external file is relative" ,
IncludedFilePath : getAbsPath ( "testdata/files" ) ,
ExternalPath : ExternalFileRelPath ,
} ,
{
Name : "relative path of directory is included and external file is absolute" ,
IncludedFilePath : "testdata/files" ,
ExternalPath : getAbsPath ( ExternalFileRelPath ) ,
} ,
}
for _ , tc := range tests {
t . Run ( tc . Name , func ( t * testing . T ) {
instAction := installAction ( t )
instAction . ExternalPaths = append ( instAction . ExternalPaths , tc . IncludedFilePath )
_ , err := instAction . Run ( buildChart ( withExternalFileTemplate ( tc . ExternalPath ) ) , vals )
expectedErr := fmt . Sprintf ( "<.Files.Get>: error calling Get: file %s not included" , tc . ExternalPath )
is . Error ( err , expectedErr )
} )
}
}
func TestInstallWhenIncludePathsPassed ( t * testing . T ) {
is := assert . New ( t )
vals := map [ string ] interface { } { }
tests := [ ] includeExternalPathTestCase {
{
Name : "relative path of file is included and external file is relative" ,
IncludedFilePath : ExternalFileRelPath ,
ExternalPath : ExternalFileRelPath ,
} ,
{
Name : "absolute path of file is included and external file is absolute" ,
IncludedFilePath : getAbsPath ( ExternalFileRelPath ) ,
ExternalPath : getAbsPath ( ExternalFileRelPath ) ,
} ,
{
Name : "relative path of directory is included and external file is relative" ,
IncludedFilePath : "testdata/files" ,
ExternalPath : ExternalFileRelPath ,
} ,
{
Name : "absolute path of directory is included and external file is absolute" ,
IncludedFilePath : getAbsPath ( "testdata/files" ) ,
ExternalPath : getAbsPath ( ExternalFileRelPath ) ,
} ,
}
for _ , tc := range tests {
t . Run ( tc . Name , func ( t * testing . T ) {
instAction := installAction ( t )
instAction . ExternalPaths = append ( instAction . ExternalPaths , tc . IncludedFilePath )
installRelease , err := instAction . Run ( buildChart ( withExternalFileTemplate ( tc . ExternalPath ) ) , vals )
is . Contains ( installRelease . Manifest , "out-of-chart-dir" )
is . NoError ( err )
} )
}
}