From 37273a55fd009b117d5d392033c30a710f5df553 Mon Sep 17 00:00:00 2001 From: anshul sharma Date: Fri, 25 Jul 2025 22:53:03 +0530 Subject: [PATCH] github getter test cases --- packer/plugin-getter/github/getter.go | 4 +-- packer/plugin-getter/plugins.go | 8 +++--- packer/plugin-getter/plugins_test.go | 36 --------------------------- 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/packer/plugin-getter/github/getter.go b/packer/plugin-getter/github/getter.go index 7f99945a7..df4fc0fe1 100644 --- a/packer/plugin-getter/github/getter.go +++ b/packer/plugin-getter/github/getter.go @@ -321,10 +321,10 @@ func (g *Getter) Init(req *plugingetter.Requirement, entry *plugingetter.Checksu func (g *Getter) Validate(opt plugingetter.GetOptions, expectedVersion string, installOpts plugingetter.BinaryInstallationOptions, entry *plugingetter.ChecksumFileEntry) error { expectedBinVersion := "v" + expectedVersion if entry.BinVersion != expectedBinVersion { - return fmt.Errorf("wrong version: '%s' does not match expected %s ", entry.BinVersion, expectedBinVersion) + return fmt.Errorf("wrong version: %s does not match expected %s", entry.BinVersion, expectedBinVersion) } if entry.Os != installOpts.OS || entry.Arch != installOpts.ARCH { - return fmt.Errorf("wrong system, expected %s_%s ", installOpts.OS, installOpts.ARCH) + return fmt.Errorf("wrong system, expected %s_%s", installOpts.OS, installOpts.ARCH) } return installOpts.CheckProtocolVersion(entry.ProtVersion) diff --git a/packer/plugin-getter/plugins.go b/packer/plugin-getter/plugins.go index 59e522e57..ca3c3d250 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -525,13 +525,13 @@ func (binOpts *BinaryInstallationOptions) CheckProtocolVersion(remoteProt string } if localVersion.Major != remoteVersion.Major { - return fmt.Errorf("Unsupported remote protocol MAJOR version %d. The current MAJOR protocol version is %d."+ - " This version of Packer can only communicate with plugins using that version.", remoteVersion.Major, localVersion.Major) + return fmt.Errorf("unsupported remote protocol MAJOR version %d. The current MAJOR protocol version is %d."+ + " This version of Packer can only communicate with plugins using that version", remoteVersion.Major, localVersion.Major) } if remoteVersion.Minor > localVersion.Minor { - return fmt.Errorf("Unsupported remote protocol MINOR version %d. The supported MINOR protocol versions are version %d and below. "+ - "Please upgrade Packer or use an older version of the plugin if possible.", remoteVersion.Minor, localVersion.Minor) + return fmt.Errorf("unsupported remote protocol MINOR version %d. The supported MINOR protocol versions are version %d and below. "+ + "Please upgrade Packer or use an older version of the plugin if possible", remoteVersion.Minor, localVersion.Minor) } return nil diff --git a/packer/plugin-getter/plugins_test.go b/packer/plugin-getter/plugins_test.go index 4ff552b8e..6a398614b 100644 --- a/packer/plugin-getter/plugins_test.go +++ b/packer/plugin-getter/plugins_test.go @@ -756,42 +756,6 @@ func (g *mockPluginGetter) Get(what string, options GetOptions) (io.ReadCloser, return io.NopCloser(read), nil } -/*func (g *mockPluginGetter) GetOfficialRelease(what string, options GetOptions) (io.ReadCloser, error) { - - var toEncode interface{} - switch what { - case "releases": - toEncode = g.Releases - case "sha256": - enc, ok := g.ChecksumFileEntries[options.version.String()] - if !ok { - return nil, fmt.Errorf("No checksum available for version %q", options.version.String()) - } - toEncode = enc - case "zip": - // Note: we'll act as if the plugin sources would always be github sources for now. - // This test will need to be updated if/when we move on to support other sources. - parts := options.PluginRequirement.Identifier.Parts() - acc := fmt.Sprintf("%s/%s/packer-plugin-%s/%s", parts[0], parts[1], parts[2], options.ExpectedZipFilename()) - - zip, found := g.Zips[acc] - if found == false { - panic(fmt.Sprintf("could not find zipfile %s. %v", acc, g.Zips)) - } - return zip, nil - default: - panic("Don't know how to get " + what) - } - - read, write := io.Pipe() - go func() { - if err := json.NewEncoder(write).Encode(toEncode); err != nil { - panic(err) - } - }() - return io.NopCloser(read), nil -}*/ - func zipFile(content map[string]string) io.ReadCloser { buff := bytes.NewBuffer(nil) zipWriter := zip.NewWriter(buff)