-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
post-processor_acc_test.go
69 lines (60 loc) · 1.52 KB
/
post-processor_acc_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
"testing"
"github.com/hashicorp/packer-plugin-sdk/acctest"
)
// Run with: PACKER_ACC=1 go test -count 1 -v post-processor_acc_test.go -timeout=120m
func TestScaffoldingPostProcessor(t *testing.T) {
testCase := &acctest.PluginTestCase{
Name: "ami-copy_post-processor_acc_test",
Setup: func() error {
return nil
},
Teardown: func() error {
return nil
},
Template: testPostProcessorHCL2Basic,
Type: "ami-copy-post-processor",
Check: func(buildCommand *exec.Cmd, logfile string) error {
if buildCommand.ProcessState != nil {
if buildCommand.ProcessState.ExitCode() != 0 {
return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
}
}
logs, err := os.Open(logfile)
if err != nil {
return fmt.Errorf("Unable find %s", logfile)
}
defer logs.Close()
logsBytes, err := ioutil.ReadAll(logs)
if err != nil {
return fmt.Errorf("Unable to read %s", logfile)
}
logsString := string(logsBytes)
postProcessorOutputLog := "post-processor mock: ami-copy-mock-config"
if matched, _ := regexp.MatchString(postProcessorOutputLog+".*", logsString); !matched {
t.Fatalf("logs doesn't contain expected foo value %q", logsString)
}
return nil
},
}
acctest.TestPlugin(t, testCase)
}
const testPostProcessorHCL2Basic = `
source "null" "basic-example" {
communicator = "none"
}
build {
sources = [
"source.null.basic-example"
]
post-processor "ami-copy" {
ami_users = ["1234567890"]
}
}
`