2013-06-18 16:49:07 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
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-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/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) {
|
|
|
|
c := NewClient(&ClientConfig{Cmd: exec.Command("i-should-not-exist")})
|
|
|
|
defer c.Kill()
|
|
|
|
|
|
|
|
_, err := c.PostProcessor()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessor_Good(t *testing.T) {
|
|
|
|
c := NewClient(&ClientConfig{Cmd: helperProcess("post-processor")})
|
|
|
|
defer c.Kill()
|
|
|
|
|
|
|
|
_, err := c.PostProcessor()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
}
|