forked from paketo-buildpacks/mri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_emitter_test.go
165 lines (142 loc) · 5.56 KB
/
log_emitter_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main_test
import (
"bytes"
"testing"
"time"
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/postal"
main "github.com/paketo-community/mri"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testLogEmitter(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
buffer *bytes.Buffer
emitter main.LogEmitter
)
it.Before(func() {
buffer = bytes.NewBuffer(nil)
emitter = main.NewLogEmitter(buffer)
})
context("SelectedDependency", func() {
it("prints details about the selected dependency", func() {
entry := packit.BuildpackPlanEntry{
Metadata: map[string]interface{}{"version-source": "some-source"},
}
dependency := postal.Dependency{
Name: "MRI",
Version: "some-version",
}
emitter.SelectedDependency(entry, dependency, time.Now())
Expect(buffer.String()).To(Equal(" Selected MRI version (using some-source): some-version\n\n"))
})
context("when the version source is missing", func() {
it("prints details about the selected dependency", func() {
dependency := postal.Dependency{
Name: "MRI",
Version: "some-version",
}
emitter.SelectedDependency(packit.BuildpackPlanEntry{}, dependency, time.Now())
Expect(buffer.String()).To(Equal(" Selected MRI version (using <unknown>): some-version\n\n"))
})
})
context("when it is within 30 days of the deprecation date", func() {
it("returns a warning that the dependency will be deprecated after the deprecation date", func() {
deprecationDate, err := time.Parse(time.RFC3339, "2021-04-01T00:00:00Z")
Expect(err).NotTo(HaveOccurred())
now := deprecationDate.Add(-29 * 24 * time.Hour)
entry := packit.BuildpackPlanEntry{
Metadata: map[string]interface{}{"version-source": "some-source"},
}
dependency := postal.Dependency{
DeprecationDate: deprecationDate,
Name: "MRI",
Version: "some-version",
}
emitter.SelectedDependency(entry, dependency, now)
Expect(buffer.String()).To(ContainSubstring(" Selected MRI version (using some-source): some-version\n"))
Expect(buffer.String()).To(ContainSubstring(" Version some-version of MRI will be deprecated after 2021-04-01.\n"))
Expect(buffer.String()).To(ContainSubstring(" Migrate your application to a supported version of MRI before this time.\n\n"))
})
})
context("when it is on the the deprecation date", func() {
it("returns a warning that the version of the dependency is no longer supported", func() {
deprecationDate, err := time.Parse(time.RFC3339, "2021-04-01T00:00:00Z")
Expect(err).NotTo(HaveOccurred())
now := deprecationDate
entry := packit.BuildpackPlanEntry{
Metadata: map[string]interface{}{"version-source": "some-source"},
}
dependency := postal.Dependency{
DeprecationDate: deprecationDate,
Name: "MRI",
Version: "some-version",
}
emitter.SelectedDependency(entry, dependency, now)
Expect(buffer.String()).To(ContainSubstring(" Selected MRI version (using some-source): some-version\n"))
Expect(buffer.String()).To(ContainSubstring(" Version some-version of MRI is deprecated.\n"))
Expect(buffer.String()).To(ContainSubstring(" Migrate your application to a supported version of MRI.\n\n"))
})
})
context("when it is after the the deprecation date", func() {
it("returns a warning that the version of the dependency is no longer supported", func() {
deprecationDate, err := time.Parse(time.RFC3339, "2021-04-01T00:00:00Z")
Expect(err).NotTo(HaveOccurred())
now := deprecationDate.Add(24 * time.Hour)
entry := packit.BuildpackPlanEntry{
Metadata: map[string]interface{}{"version-source": "some-source"},
}
dependency := postal.Dependency{
DeprecationDate: deprecationDate,
Name: "MRI",
Version: "some-version",
}
emitter.SelectedDependency(entry, dependency, now)
Expect(buffer.String()).To(ContainSubstring(" Selected MRI version (using some-source): some-version\n"))
Expect(buffer.String()).To(ContainSubstring(" Version some-version of MRI is deprecated.\n"))
Expect(buffer.String()).To(ContainSubstring(" Migrate your application to a supported version of MRI.\n\n"))
})
})
})
context("Candidates", func() {
it("prints a formatted map of version source inputs", func() {
emitter.Candidates([]packit.BuildpackPlanEntry{
{
Name: "mri",
Version: "package-json-version",
Metadata: map[string]interface{}{
"version-source": "package.json",
},
},
{
Name: "mri",
Version: "other-version",
},
{
Name: "mri",
Version: "buildpack-yml-version",
Metadata: map[string]interface{}{
"version-source": "buildpack.yml",
},
},
{
Name: "mri",
},
})
Expect(buffer.String()).To(ContainSubstring(" Candidate version sources (in priority order):"))
Expect(buffer.String()).To(ContainSubstring(" buildpack.yml -> \"buildpack-yml-version\""))
Expect(buffer.String()).To(ContainSubstring(" <unknown> -> \"other-version\""))
Expect(buffer.String()).To(ContainSubstring(" <unknown> -> \"*\""))
})
})
context("Environment", func() {
it("prints details about the environment", func() {
emitter.Environment(packit.Environment{
"GEM_PATH.override": "/some/path",
})
Expect(buffer.String()).To(ContainSubstring(" Configuring environment"))
Expect(buffer.String()).To(ContainSubstring(" GEM_PATH -> \"/some/path\""))
})
})
}