2018-11-22 21:33:34 -05:00
|
|
|
package digitaloceanimport
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2018-11-22 21:33:34 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
|
2020-12-01 17:48:55 -05:00
|
|
|
var _ packersdk.PostProcessor = new(PostProcessor)
|
2018-11-22 21:33:34 -05:00
|
|
|
}
|
2020-09-01 10:59:01 -04:00
|
|
|
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|