From bc6d2a3ff47590a330cefb3ae13737f9f17e4b8d Mon Sep 17 00:00:00 2001 From: anshul sharma Date: Sat, 26 Jul 2025 11:00:07 +0530 Subject: [PATCH] added test cases for getters --- packer/plugin-getter/plugins_test.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packer/plugin-getter/plugins_test.go b/packer/plugin-getter/plugins_test.go index 3b1f9ca8b..caf4632c3 100644 --- a/packer/plugin-getter/plugins_test.go +++ b/packer/plugin-getter/plugins_test.go @@ -9,9 +9,6 @@ import ( "crypto/sha256" "encoding/json" "fmt" - "github.com/google/go-cmp/cmp" - "github.com/hashicorp/go-version" - "github.com/hashicorp/packer/hcl2template/addrs" "io" "log" "os" @@ -19,6 +16,10 @@ import ( "runtime" "strings" "testing" + + "github.com/google/go-cmp/cmp" + "github.com/hashicorp/go-version" + "github.com/hashicorp/packer/hcl2template/addrs" ) var ( @@ -84,6 +85,7 @@ func TestRequirement_InstallLatestFromGithub(t *testing.T) { args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v1.2.3"}, }, @@ -119,6 +121,7 @@ func TestRequirement_InstallLatestFromGithub(t *testing.T) { args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v1.2.3"}, {Version: "v1.2.4"}, @@ -160,6 +163,7 @@ func TestRequirement_InstallLatestFromGithub(t *testing.T) { args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v1.2.3"}, {Version: "v1.2.4"}, @@ -211,6 +215,7 @@ echo '{"version":"v2.10.0","api_version":"x6.0"}'`, args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v1.2.3"}, {Version: "v1.2.4"}, @@ -263,6 +268,7 @@ echo '{"version":"v2.10.1","api_version":"x6.1"}'`, args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v1.2.3"}, {Version: "v1.2.4"}, @@ -315,6 +321,7 @@ echo '{"version":"v2.10.0","api_version":"x6.1"}'`, args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v2.10.0"}, }, @@ -355,6 +362,7 @@ echo '{"version":"v2.10.0","api_version":"x6.1"}'`, args{InstallOptions{ []Getter{ &mockPluginGetter{ + Name: "github.com", Releases: []Release{ {Version: "v2.10.0"}, }, @@ -689,6 +697,7 @@ type mockPluginGetter struct { Releases []Release ChecksumFileEntries map[string][]ChecksumFileEntry Zips map[string]io.ReadCloser + Name string } func (g *mockPluginGetter) Init(req *Requirement, entry *ChecksumFileEntry) error { @@ -708,7 +717,11 @@ func (g *mockPluginGetter) Validate(opt GetOptions, expectedVersion string, inst } func (g *mockPluginGetter) ExpectedFileName(pr *Requirement, version string, entry *ChecksumFileEntry, zipFileName string) string { - return zipFileName + if g.Name == "github.com" { + return zipFileName + } + + return "" } func (g *mockPluginGetter) Get(what string, options GetOptions) (io.ReadCloser, error) {