This repository has been archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuilder_acc_test.go
99 lines (85 loc) · 2.54 KB
/
builder_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package exoscale
import (
"errors"
"fmt"
"os"
"testing"
pkrtesting "github.com/hashicorp/packer/helper/builder/testing"
"github.com/hashicorp/packer/packer"
)
var (
testAccTemplateName = "test-packer-builder-exoscale"
testAccTemplateZone = "ch-gva-2"
testAccTemplateDescription = "Built with Packer"
testAccTemplateUsername = "packer"
testAccBuilderTemplate = fmt.Sprintf(`{
"variables": {
"api_key": "{{env `+"`EXOSCALE_API_KEY`"+`}}",
"api_secret": "{{env `+"`EXOSCALE_API_SECRET`"+`}}"
},
"builders": [{
"type": "test",
"api_key": "{{user `+"`api_key`"+`}}",
"api_secret": "{{user `+"`api_secret`"+`}}",
"instance_template": "Linux Ubuntu 20.04 LTS 64-bit",
"template_zone": "%s",
"template_name": "%s",
"template_description": "%s",
"template_username": "%s",
"ssh_username": "ubuntu"
}]
}`,
testAccTemplateZone,
testAccTemplateName,
testAccTemplateDescription,
testAccTemplateUsername,
)
)
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("EXOSCALE_API_KEY"); v == "" {
t.Fatal("EXOSCALE_API_KEY must be set for acceptance tests")
}
if v := os.Getenv("EXOSCALE_API_SECRET"); v == "" {
t.Fatal("EXOSCALE_API_SECRET must be set for acceptance tests")
}
}
func testAccCheckBuilderArtifact(artifacts []packer.Artifact) error {
if len(artifacts) != 1 {
return fmt.Errorf("expected 1 artifact, got %d", len(artifacts))
}
artifact := artifacts[0].(*Artifact)
if artifact.template.ID == nil {
return fmt.Errorf("artifact template ID is not set")
}
if artifact.template.Name != testAccTemplateName {
return fmt.Errorf("expected template name %q, got %q",
testAccTemplateName,
artifact.template.Name)
}
if artifact.template.ZoneName != testAccTemplateZone {
return fmt.Errorf("expected template zone %q, got %q",
testAccTemplateZone,
artifact.template.ZoneName)
}
if artifact.template.BootMode != defaultTemplateBootMode {
return fmt.Errorf("expected template boot mode %q, got %q",
defaultTemplateBootMode,
artifact.template.BootMode)
}
if username, ok := artifact.template.Details["username"]; !ok {
return errors.New("artifact username not set")
} else if username != testAccTemplateUsername {
return fmt.Errorf("expected template username %q, got %q",
testAccTemplateUsername,
username)
}
return nil
}
func TestAccBuilder(t *testing.T) {
pkrtesting.Test(t, pkrtesting.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Builder: &Builder{},
Template: testAccBuilderTemplate,
Check: testAccCheckBuilderArtifact,
})
}