-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathfromartifact_example_test.go
More file actions
70 lines (54 loc) · 1.59 KB
/
fromartifact_example_test.go
File metadata and controls
70 lines (54 loc) · 1.59 KB
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
package image_test
import (
"fmt"
"github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
)
type simpleArtifact struct {
image_id string
}
func (a *simpleArtifact) BuilderId() string {
return "example.happycloud"
}
func (a *simpleArtifact) Files() []string {
return nil
}
func (a *simpleArtifact) Id() string {
return a.image_id
}
func (a *simpleArtifact) String() string {
return fmt.Sprintf("Imported image URL: %s", a.Id())
}
func (a *simpleArtifact) State(name string) interface{} {
return nil
}
func (a *simpleArtifact) Destroy() error {
return nil
}
func ExampleFromArtifact() {
a := &simpleArtifact{
image_id: "service-id-123",
}
hcimage, _ := image.FromArtifact(a)
fmt.Printf("%#v", *hcimage)
// Output:
// image.Image{ImageID:"service-id-123", ProviderName:"example.happycloud", ProviderRegion:"", Labels:map[string]string{}}
}
func ExampleWithProvider() {
a := &simpleArtifact{
image_id: "service-id-123",
}
// This example also includes an override for the ProviderRegion to illustrate how ArtifactOverrideFunc(s) can be chained.
hcimage, _ := image.FromArtifact(a, image.WithProvider("happycloud"), image.WithRegion("west"))
fmt.Printf("%#v", *hcimage)
// Output:
// image.Image{ImageID:"service-id-123", ProviderName:"happycloud", ProviderRegion:"west", Labels:map[string]string{}}
}
func ExampleSetLabels() {
a := &simpleArtifact{
image_id: "service-id-123",
}
hcimage, _ := image.FromArtifact(a, image.SetLabels(map[string]interface{}{"kernel": "4.0", "python": "3.5"}))
fmt.Printf("%v", hcimage.Labels)
// Unordered output:
// map[kernel:4.0 python:3.5]
}