github.com/hashicorp/packer@v1.14.3/packer/cmd_post_processor_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package packer
     5  
     6  import (
     7  	"context"
     8  	"os/exec"
     9  	"testing"
    10  
    11  	"github.com/hashicorp/hcl/v2/hcldec"
    12  	packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
    13  )
    14  
    15  type helperPostProcessor byte
    16  
    17  func (helperPostProcessor) ConfigSpec() hcldec.ObjectSpec { return nil }
    18  
    19  func (helperPostProcessor) Configure(...interface{}) error {
    20  	return nil
    21  }
    22  
    23  func (helperPostProcessor) PostProcess(context.Context, packersdk.Ui, packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {
    24  	return nil, false, false, nil
    25  }
    26  
    27  func TestPostProcessor_NoExist(t *testing.T) {
    28  	c := NewClient(&PluginClientConfig{Cmd: exec.Command("i-should-not-exist")})
    29  	defer c.Kill()
    30  
    31  	_, err := c.PostProcessor()
    32  	if err == nil {
    33  		t.Fatal("should have error")
    34  	}
    35  }
    36  
    37  func TestPostProcessor_Good(t *testing.T) {
    38  	c := NewClient(&PluginClientConfig{Cmd: helperProcess("post-processor")})
    39  	defer c.Kill()
    40  
    41  	_, err := c.PostProcessor()
    42  	if err != nil {
    43  		t.Fatalf("should not have error: %s", err)
    44  	}
    45  }