From f7f7265114c1016ceb374860872f4c3c949357da Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 18 Jul 2024 13:41:32 +0000 Subject: [PATCH] backport of commit 3e9cd6536e220960da3ed5d2c9612600720f3aa9 --- builder/file/builder.go | 2 -- builder/null/config_test.go | 13 --------- command/config_file_unix.go | 11 ------- command/config_file_windows.go | 11 ------- command/init_test.go | 13 --------- hcl2template/common_test.go | 29 ------------------- hcl2template/functions.go | 10 ------- hcl2template/types.packer_config_test.go | 1 - packer/plugin-getter/plugins_test.go | 4 --- packer/plugin.go | 5 ---- packer/plugin_discover_test.go | 29 ------------------- packer/provisioner.go | 5 ---- .../checksum/post-processor_test.go | 2 -- 13 files changed, 135 deletions(-) delete mode 100644 command/config_file_unix.go delete mode 100644 command/config_file_windows.go diff --git a/builder/file/builder.go b/builder/file/builder.go index 0f79c958fe8..34c9fa2cd2f 100644 --- a/builder/file/builder.go +++ b/builder/file/builder.go @@ -16,7 +16,6 @@ import ( "path/filepath" "github.com/hashicorp/hcl/v2/hcldec" - "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) @@ -24,7 +23,6 @@ const BuilderId = "packer.file" type Builder struct { config Config - runner multistep.Runner } func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } diff --git a/builder/null/config_test.go b/builder/null/config_test.go index 67d35f66972..72272397ae5 100644 --- a/builder/null/config_test.go +++ b/builder/null/config_test.go @@ -18,19 +18,6 @@ func testConfig() map[string]interface{} { } } -func testConfigStruct(t *testing.T) *Config { - var c Config - warns, errs := c.Prepare(testConfig()) - if len(warns) > 0 { - t.Fatalf("bad: %#v", len(warns)) - } - if errs != nil { - t.Fatalf("bad: %#v", errs) - } - - return &c -} - func testConfigErr(t *testing.T, warns []string, err error) { if len(warns) > 0 { t.Fatalf("bad: %#v", warns) diff --git a/command/config_file_unix.go b/command/config_file_unix.go deleted file mode 100644 index ec3932f9e0b..00000000000 --- a/command/config_file_unix.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -//go:build darwin || freebsd || linux || netbsd || openbsd || solaris -// +build darwin freebsd linux netbsd openbsd solaris - -package command - -const ( - defaultConfigDir = ".packer.d" -) diff --git a/command/config_file_windows.go b/command/config_file_windows.go deleted file mode 100644 index ede0a618687..00000000000 --- a/command/config_file_windows.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -//go:build windows -// +build windows - -package command - -const ( - defaultConfigDir = "packer.d" -) diff --git a/command/init_test.go b/command/init_test.go index 4a0c44be945..b8a02f3a118 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -6,7 +6,6 @@ package command import ( - "context" "fmt" "log" "os" @@ -16,7 +15,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/go-getter/v2" "github.com/hashicorp/packer-plugin-sdk/acctest" "golang.org/x/mod/sumdb/dirhash" ) @@ -312,17 +310,6 @@ func (key skipInitTestUnlessEnVar) fn(t *testing.T, tc testCaseInit) { // } } -type initTestGoGetPlugin struct { - Src string - Dst string -} - -func (opts initTestGoGetPlugin) fn(t *testing.T, _ testCaseInit) { - if _, err := getter.Get(context.Background(), opts.Dst, opts.Src); err != nil { - t.Fatalf("get: %v", err) - } -} - // TestInitCmd aims to test the init command, with output validation func TestInitCmd(t *testing.T) { tests := []struct { diff --git a/hcl2template/common_test.go b/hcl2template/common_test.go index 831ce5d3596..08cdc3f6782 100644 --- a/hcl2template/common_test.go +++ b/hcl2template/common_test.go @@ -205,17 +205,6 @@ var ( Datasource: "string", } - basicMockBuilder = &MockBuilder{ - Config: MockConfig{ - NestedMockConfig: builderBasicNestedMockConfig, - Nested: builderBasicNestedMockConfig, - NestedSlice: []NestedMockConfig{ - builderBasicNestedMockConfig, - builderBasicNestedMockConfig, - }, - }, - } - basicMockProvisioner = &MockProvisioner{ Config: MockConfig{ NotSquashed: "value ", @@ -273,17 +262,6 @@ var ( NestedSlice: []NestedMockConfig{}, }, } - basicMockCommunicator = &MockCommunicator{ - Config: MockConfig{ - NestedMockConfig: basicNestedMockConfig, - Nested: basicNestedMockConfig, - NestedSlice: []NestedMockConfig{ - { - Tags: []MockTag{}, - }, - }, - }, - } emptyMockBuilder = &MockBuilder{ Config: MockConfig{ @@ -295,13 +273,6 @@ var ( }, } - emptyMockProvisioner = &MockProvisioner{ - Config: MockConfig{ - NestedMockConfig: NestedMockConfig{Tags: []MockTag{}}, - NestedSlice: []NestedMockConfig{}, - }, - } - dynamicTagList = []MockTag{ { Key: "first_tag_key", diff --git a/hcl2template/functions.go b/hcl2template/functions.go index 5340f34dded..7089201bc2d 100644 --- a/hcl2template/functions.go +++ b/hcl2template/functions.go @@ -6,7 +6,6 @@ package hcl2template import ( "bytes" "encoding/base64" - "fmt" "github.com/hashicorp/go-cty-funcs/cidr" "github.com/hashicorp/go-cty-funcs/collection" @@ -226,12 +225,3 @@ var TextDecodeBase64Func = function.New(&function.Spec{ return cty.StringVal(string(decoded)), nil }, }) - -var unimplFunc = function.New(&function.Spec{ - Type: func([]cty.Value) (cty.Type, error) { - return cty.DynamicPseudoType, fmt.Errorf("function not yet implemented") - }, - Impl: func([]cty.Value, cty.Type) (cty.Value, error) { - return cty.DynamicVal, fmt.Errorf("function not yet implemented") - }, -}) diff --git a/hcl2template/types.packer_config_test.go b/hcl2template/types.packer_config_test.go index fb3a433f8b0..708a80f76ec 100644 --- a/hcl2template/types.packer_config_test.go +++ b/hcl2template/types.packer_config_test.go @@ -21,7 +21,6 @@ import ( var ( refVBIsoUbuntu1204 = SourceRef{Type: "virtualbox-iso", Name: "ubuntu-1204"} refAWSEBSUbuntu1604 = SourceRef{Type: "amazon-ebs", Name: "ubuntu-1604"} - refAWSV3MyImage = SourceRef{Type: "amazon-v3-ebs", Name: "my-image"} refNull = SourceRef{Type: "null", Name: "test"} pTrue = pointerToBool(true) ) diff --git a/packer/plugin-getter/plugins_test.go b/packer/plugin-getter/plugins_test.go index de84cc8a923..ca53500b1d7 100644 --- a/packer/plugin-getter/plugins_test.go +++ b/packer/plugin-getter/plugins_test.go @@ -26,10 +26,6 @@ var ( pluginFolderOne = filepath.Join("testdata", "plugins") pluginFolderTwo = filepath.Join("testdata", "plugins_2") - - pluginFolderThree = filepath.Join("testdata", "plugins_3") - - pluginFolderWrongChecksums = filepath.Join("testdata", "wrong_checksums") ) func TestChecksumFileEntry_init(t *testing.T) { diff --git a/packer/plugin.go b/packer/plugin.go index 5939d6aa6ab..79326f23af2 100644 --- a/packer/plugin.go +++ b/packer/plugin.go @@ -20,11 +20,6 @@ import ( plugingetter "github.com/hashicorp/packer/packer/plugin-getter" ) -var defaultChecksummer = plugingetter.Checksummer{ - Type: "sha256", - Hash: sha256.New(), -} - // PluginConfig helps load and use packer plugins type PluginConfig struct { PluginDirectory string diff --git a/packer/plugin_discover_test.go b/packer/plugin_discover_test.go index de50136cdc8..9003cffa0d4 100644 --- a/packer/plugin_discover_test.go +++ b/packer/plugin_discover_test.go @@ -250,35 +250,6 @@ func TestMultiPlugin_defaultName_each_plugin_type(t *testing.T) { } } -func generateFakePlugins(dirname string, pluginNames []string) (string, []string, func(), error) { - dir, err := os.MkdirTemp("", dirname) - if err != nil { - return "", nil, nil, fmt.Errorf("failed to create temporary test directory: %v", err) - } - - cleanUpFunc := func() { - os.RemoveAll(dir) - } - - var suffix string - if runtime.GOOS == "windows" { - suffix = ".exe" - } - - plugins := make([]string, len(pluginNames)) - for i, plugin := range pluginNames { - plug := filepath.Join(dir, plugin+suffix) - plugins[i] = plug - _, err := os.Create(plug) - if err != nil { - cleanUpFunc() - return "", nil, nil, fmt.Errorf("failed to create temporary plugin file (%s): %v", plug, err) - } - } - - return dir, plugins, cleanUpFunc, nil -} - // TestHelperProcess isn't a real test. It's used as a helper process // for multi-component plugin tests. func TestHelperPlugins(t *testing.T) { diff --git a/packer/provisioner.go b/packer/provisioner.go index c7761adeb5f..81dce0ecfc0 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "log" - "sync" "time" "github.com/hashicorp/hcl/v2/hcldec" @@ -205,10 +204,6 @@ func (r *RetriedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, com // press before the provisioner is actually run. type DebuggedProvisioner struct { Provisioner packersdk.Provisioner - - cancelCh chan struct{} - doneCh chan struct{} - lock sync.Mutex } func (p *DebuggedProvisioner) ConfigSpec() hcldec.ObjectSpec { return p.ConfigSpec() } diff --git a/post-processor/checksum/post-processor_test.go b/post-processor/checksum/post-processor_test.go index 6a08f029735..cf871432d9d 100644 --- a/post-processor/checksum/post-processor_test.go +++ b/post-processor/checksum/post-processor_test.go @@ -17,8 +17,6 @@ import ( "github.com/hashicorp/packer/builder/file" ) -const expectedFileContents = "Hello world!" - func TestChecksumSHA1(t *testing.T) { const config = ` {