File: post-processor_test.go

package info (click to toggle)
packer 1.6.6%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 32,016 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (39 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package digitaloceanimport

import (
	"testing"

	packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
)

func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
	var _ packersdk.PostProcessor = new(PostProcessor)
}

func TestPostProcessor_ImageArtifactExtraction(t *testing.T) {
	tt := []struct {
		Name          string
		Source        string
		Artifacts     []string
		ExpectedError string
	}{
		{Name: "EmptyArtifacts", ExpectedError: "no artifacts were provided"},
		{Name: "SingleArtifact", Source: "Sample.img", Artifacts: []string{"Sample.img"}},
		{Name: "SupportedArtifact", Source: "Example.tar.xz", Artifacts: []string{"Sample", "SomeZip.zip", "Example.tar.xz"}},
		{Name: "FirstSupportedArtifact", Source: "SomeVMDK.vmdk", Artifacts: []string{"Sample", "SomeVMDK.vmdk", "Example.xz"}},
		{Name: "NonSupportedArtifact", Artifacts: []string{"Sample", "SomeZip.zip", "Example.xz"}, ExpectedError: "no valid image file found"},
	}

	for _, tc := range tt {
		tc := tc
		source, err := extractImageArtifact(tc.Artifacts)

		if tc.Source != source {
			t.Errorf("expected the source to be %q, but got %q", tc.Source, source)
		}

		if err != nil && (tc.ExpectedError != err.Error()) {
			t.Errorf("unexpected error received; expected %q, but got %q", tc.ExpectedError, err.Error())
		}
	}
}