2021-02-02 12:05:04 -05:00
|
|
|
package packer
|
2013-06-18 16:49:07 -04:00
|
|
|
|
|
|
|
import (
|
2019-03-22 09:56:02 -04:00
|
|
|
"context"
|
2013-06-18 16:49:07 -04:00
|
|
|
"os/exec"
|
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2013-06-18 16:49:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type helperPostProcessor byte
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (helperPostProcessor) ConfigSpec() hcldec.ObjectSpec { return nil }
|
|
|
|
|
2013-07-01 17:59:23 -04:00
|
|
|
func (helperPostProcessor) Configure(...interface{}) error {
|
2013-06-18 16:49:07 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
func (helperPostProcessor) PostProcess(context.Context, packersdk.Ui, packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {
|
2019-04-03 14:32:49 -04:00
|
|
|
return nil, false, false, nil
|
2013-06-18 16:49:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessor_NoExist(t *testing.T) {
|
2021-02-02 12:05:04 -05:00
|
|
|
c := NewClient(&PluginClientConfig{Cmd: exec.Command("i-should-not-exist")})
|
2013-06-18 16:49:07 -04:00
|
|
|
defer c.Kill()
|
|
|
|
|
|
|
|
_, err := c.PostProcessor()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessor_Good(t *testing.T) {
|
2021-02-02 12:05:04 -05:00
|
|
|
c := NewClient(&PluginClientConfig{Cmd: helperProcess("post-processor")})
|
2013-06-18 16:49:07 -04:00
|
|
|
defer c.Kill()
|
|
|
|
|
|
|
|
_, err := c.PostProcessor()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
}
|