Skip to content

Commit

Permalink
add transfer_files to prepare and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Dec 20, 2024
1 parent 4c0a37f commit 4acd1d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
6 changes: 5 additions & 1 deletion provisioner/testinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type Config struct {
PytestPath string `mapstructure:"pytest_path" required:"false"`
Sudo bool `mapstructure:"sudo" required:"false"`
SudoUser string `mapstructure:"sudo_user" required:"false"`
TransferFiles bool `mapstructure:"transfer_files" required:"false"`
TestFiles []string `mapstructure:"test_files" required:"false"`
TransferFiles bool `mapstructure:"transfer_files" required:"false"`
Verbose int `mapstructure:"verbose" required:"false"`

ctx interpolate.Context
Expand Down Expand Up @@ -83,6 +83,10 @@ func (provisioner *Provisioner) Prepare(raws ...interface{}) error {
log.Printf("installation command on the temporary Packer instance prior to Testinfra test execution is: %s", strings.Join(provisioner.config.InstallCmd, " "))
}

if provisioner.config.TransferFiles {
log.Print("test files will be copied to the temporary Packer instance prior to Testinfra test execution")
}

// no validation of xdist installation
if provisioner.config.Parallel {
log.Print("pytest-xdist validation does not occur with local execution")
Expand Down
4 changes: 2 additions & 2 deletions provisioner/testinfra.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 18 additions & 13 deletions provisioner/testinfra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ var CI bool = os.Getenv("CIRCLECI") == "true" || os.Getenv("GITHUB_ACTIONS") ==

// global helper vars for tests
var basicConfig = &Config{
Chdir: "/tmp",
InstallCmd: []string{"/bin/false"},
Keyword: "not slow",
Local: false,
Marker: "fast",
Parallel: true,
PytestPath: "/usr/local/bin/py.test",
Sudo: true,
SudoUser: "fooman",
TestFiles: []string{"../fixtures/test.py"},
Verbose: 2,
Chdir: "/tmp",
InstallCmd: []string{"/bin/false"},
Keyword: "not slow",
Local: false,
Marker: "fast",
Parallel: true,
PytestPath: "/usr/local/bin/py.test",
Sudo: true,
SudoUser: "fooman",
TransferFiles: false,
TestFiles: []string{"../fixtures/test.py"},
Verbose: 2,
}

// test basic config for packer template/config data
Expand All @@ -34,7 +35,7 @@ func TestProvisionerConfig(test *testing.T) {
config: *basicConfig,
}

if provisioner.config.PytestPath != basicConfig.PytestPath || !slices.Equal(provisioner.config.TestFiles, basicConfig.TestFiles) || provisioner.config.Chdir != basicConfig.Chdir || !slices.Equal(provisioner.config.InstallCmd, basicConfig.InstallCmd) || provisioner.config.Keyword != basicConfig.Keyword || provisioner.config.Local != basicConfig.Local || provisioner.config.Marker != basicConfig.Marker || provisioner.config.Parallel != basicConfig.Parallel || provisioner.config.Sudo != basicConfig.Sudo || provisioner.config.SudoUser != basicConfig.SudoUser || provisioner.config.Verbose != basicConfig.Verbose {
if provisioner.config.PytestPath != basicConfig.PytestPath || provisioner.config.TransferFiles != basicConfig.TransferFiles || !slices.Equal(provisioner.config.TestFiles, basicConfig.TestFiles) || provisioner.config.Chdir != basicConfig.Chdir || !slices.Equal(provisioner.config.InstallCmd, basicConfig.InstallCmd) || provisioner.config.Keyword != basicConfig.Keyword || provisioner.config.Local != basicConfig.Local || provisioner.config.Marker != basicConfig.Marker || provisioner.config.Parallel != basicConfig.Parallel || provisioner.config.Sudo != basicConfig.Sudo || provisioner.config.SudoUser != basicConfig.SudoUser || provisioner.config.Verbose != basicConfig.Verbose {
test.Errorf("provisioner config struct not initialized correctly")
}
}
Expand All @@ -59,7 +60,7 @@ func TestProvisionerPrepareBasic(test *testing.T) {
}
}

// test provisioner prepare with minimal config (essentially default setting)
// test provisioner prepare with minimal config (essentially default settings)
func TestProvisionerPrepareMinimal(test *testing.T) {
var provisioner Provisioner

Expand Down Expand Up @@ -111,6 +112,10 @@ func TestProvisionerPrepareMinimal(test *testing.T) {
if len(provisioner.config.TestFiles) != 0 {
test.Errorf("default setting for TestFiles is incorrect: %+q", provisioner.config.TestFiles)
}

if provisioner.config.TransferFiles {
test.Errorf("default false setting for TransferFiles is incorrect: %t", provisioner.config.TransferFiles)
}
}

// test provisioner prepare defaults to empty slice for test files
Expand Down

0 comments on commit 4acd1d2

Please sign in to comment.