github.com/hashicorp/packer@v1.14.3/packer_test/plugin_tests/init_test.go (about)

     1  package plugin_tests
     2  
     3  import (
     4  	"github.com/hashicorp/packer/packer_test/common/check"
     5  )
     6  
     7  func (ts *PackerPluginTestSuite) TestPackerInitForce() {
     8  	ts.SkipNoAcc()
     9  
    10  	pluginPath := ts.MakePluginDir()
    11  	defer pluginPath.Cleanup()
    12  
    13  	ts.Run("installs any missing plugins", func() {
    14  		ts.PackerCommand().UsePluginDir(pluginPath).
    15  			SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl").
    16  			Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout))
    17  	})
    18  
    19  	ts.Run("reinstalls plugins matching version constraints", func() {
    20  		ts.PackerCommand().UsePluginDir(pluginPath).
    21  			SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl").
    22  			Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout))
    23  	})
    24  }
    25  
    26  func (ts *PackerPluginTestSuite) TestPackerInitUpgrade() {
    27  	ts.SkipNoAcc()
    28  
    29  	pluginPath := ts.MakePluginDir()
    30  	defer pluginPath.Cleanup()
    31  
    32  	cmd := ts.PackerCommand().UsePluginDir(pluginPath)
    33  	cmd.SetArgs("plugins", "install", "github.com/hashicorp/hashicups", "1.0.1")
    34  	cmd.SetAssertFatal()
    35  	cmd.Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.1", check.GrepStdout))
    36  
    37  	ts.Run("upgrades a plugin to the latest matching version constraints", func() {
    38  		ts.PackerCommand().UsePluginDir(pluginPath).
    39  			SetArgs("init", "--upgrade", "./templates/init/hashicups.pkr.hcl").
    40  			Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout))
    41  	})
    42  }
    43  
    44  func (ts *PackerPluginTestSuite) TestPackerInitWithNonGithubSource() {
    45  	pluginPath := ts.MakePluginDir()
    46  	defer pluginPath.Cleanup()
    47  
    48  	ts.Run("try installing from a non-github source, should fail", func() {
    49  		ts.PackerCommand().UsePluginDir(pluginPath).
    50  			SetArgs("init", "./templates/init/non_gh.pkr.hcl").
    51  			Assert(check.MustFail(), check.Grep(`doesn't appear to be a valid "github.com" source address`, check.GrepStdout))
    52  	})
    53  
    54  	ts.Run("manually install plugin to the expected source", func() {
    55  		ts.PackerCommand().UsePluginDir(pluginPath).
    56  			SetArgs("plugins", "install", "--path", ts.GetPluginPath(ts.T(), "1.0.10"), "hubgit.com/hashicorp/tester").
    57  			Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1.0.10", check.GrepStdout))
    58  	})
    59  
    60  	ts.Run("re-run packer init on same template, should succeed silently", func() {
    61  		ts.PackerCommand().UsePluginDir(pluginPath).
    62  			SetArgs("init", "./templates/init/non_gh.pkr.hcl").
    63  			Assert(check.MustSucceed(),
    64  				check.MkPipeCheck("no output in stdout").SetTester(check.ExpectEmptyInput()).SetStream(check.OnlyStdout))
    65  	})
    66  }
    67  
    68  func (ts *PackerPluginTestSuite) TestPackerInitWithMixedVersions() {
    69  	ts.SkipNoAcc()
    70  
    71  	pluginPath := ts.MakePluginDir()
    72  	defer pluginPath.Cleanup()
    73  
    74  	ts.Run("skips the plugin installation with mixed versions before exiting with an error", func() {
    75  		ts.PackerCommand().UsePluginDir(pluginPath).
    76  			SetArgs("init", "./templates/init/mixed_versions.pkr.hcl").
    77  			Assert(check.MustFail(),
    78  				check.Grep("binary reported a pre-release version of 10.7.3-dev", check.GrepStdout))
    79  	})
    80  }