-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathartifact_test.go
More file actions
102 lines (87 loc) · 2.36 KB
/
artifact_test.go
File metadata and controls
102 lines (87 loc) · 2.36 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
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
100
101
102
//go:build !integration
package upcloud //nolint:testpackage // not all fields can be exported in Artifact
import (
"fmt"
"testing"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
"github.com/stretchr/testify/assert"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
)
func TestArtifact_impl(t *testing.T) {
t.Parallel()
var _ packersdk.Artifact = new(Artifact)
}
func TestArtifact_Id(t *testing.T) {
t.Parallel()
uuid1 := "some-uuid-1"
uuid2 := "some-uuid-2"
expected := fmt.Sprintf("%s,%s", uuid1, uuid2)
templates := make([]*upcloud.Storage, 0, 2)
templates = append(templates, &upcloud.Storage{UUID: uuid1}, &upcloud.Storage{UUID: uuid2})
a := &Artifact{Templates: templates}
result := a.Id()
if result != expected {
t.Errorf("Expected: %q, got: %q", expected, result)
}
}
func TestArtifact_String(t *testing.T) {
t.Parallel()
expected := `Storage template created, UUID: some-uuid`
templates := make([]*upcloud.Storage, 0, 1)
templates = append(templates, &upcloud.Storage{UUID: "some-uuid"})
a := &Artifact{Templates: templates}
result := a.String()
if result != expected {
t.Errorf("Expected: %q, got: %q", expected, result)
}
}
func TestArtifact_Metadata(t *testing.T) {
t.Parallel()
templates := make([]*upcloud.Storage, 0, 2)
templates = append(templates,
&upcloud.Storage{
UUID: "some-uuid",
Size: 10,
Title: "some-title",
Zone: "fi-hel1",
},
&upcloud.Storage{
UUID: "some-other-uuid",
Size: 10,
Title: "some-title",
Zone: "fi-hel2",
},
)
a := &Artifact{
Templates: templates,
config: &Config{
Zone: "fi-hel1",
CloneZones: []string{"fi-hel2"},
TemplatePrefix: "prefix",
},
StateData: map[string]interface{}{
"source_template_title": "source-title",
"source_template_uuid": "source-uuid",
},
}
result := a.State(image.ArtifactStateURI)
got, ok := result.([]*image.Image)
if !ok {
t.Fatalf("Expected []*image.Image, got %T", result)
}
want := &image.Image{
ImageID: "some-uuid",
ProviderName: "upcloud",
ProviderRegion: "fi-hel1",
Labels: map[string]string{
"source": "source-title",
"source_id": "source-uuid",
"name": "some-title",
"name_prefix": "prefix",
"size": "10",
},
SourceImageID: "source-uuid",
}
assert.Equal(t, want, got[0])
}