-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds function that prints out dependency information as well as deprecation warnings Signed-off-by: Forest Eckhardt <[email protected]>
- Loading branch information
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package scribe | ||
|
||
import ( | ||
"io" | ||
"time" | ||
|
||
"github.com/paketo-buildpacks/packit" | ||
"github.com/paketo-buildpacks/packit/postal" | ||
) | ||
|
||
type Emitter struct { | ||
// Logger is embedded and therefore delegates all of its functions to the | ||
// Emitter. | ||
Logger | ||
} | ||
|
||
func NewEmitter(output io.Writer) Emitter { | ||
return Emitter{ | ||
Logger: NewLogger(output), | ||
} | ||
} | ||
|
||
func (e Emitter) SelectedDependency(entry packit.BuildpackPlanEntry, dependency postal.Dependency, now time.Time) { | ||
source, ok := entry.Metadata["version-source"].(string) | ||
if !ok { | ||
source = "<unknown>" | ||
} | ||
|
||
e.Subprocess("Selected %s version (using %s): %s", dependency.Name, source, dependency.Version) | ||
|
||
if (dependency.DeprecationDate != time.Time{}) { | ||
deprecationDate := dependency.DeprecationDate | ||
switch { | ||
case (deprecationDate.Add(-30*24*time.Hour).Before(now) && deprecationDate.After(now)): | ||
e.Action("Version %s of %s will be deprecated after %s.", dependency.Version, dependency.Name, dependency.DeprecationDate.Format("2006-01-02")) | ||
e.Action("Migrate your application to a supported version of %s before this time.", dependency.Name) | ||
case (deprecationDate == now || deprecationDate.Before(now)): | ||
e.Action("Version %s of %s is deprecated.", dependency.Version, dependency.Name) | ||
e.Action("Migrate your application to a supported version of %s.", dependency.Name) | ||
} | ||
} | ||
e.Break() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package scribe_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
"time" | ||
|
||
"github.com/paketo-buildpacks/packit" | ||
"github.com/paketo-buildpacks/packit/postal" | ||
"github.com/paketo-buildpacks/packit/scribe" | ||
"github.com/sclevine/spec" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func testEmitter(t *testing.T, context spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
|
||
buffer *bytes.Buffer | ||
emitter scribe.Emitter | ||
) | ||
|
||
it.Before(func() { | ||
buffer = bytes.NewBuffer(nil) | ||
emitter = scribe.NewEmitter(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: "Some Dependency", | ||
Version: "some-version", | ||
} | ||
|
||
emitter.SelectedDependency(entry, dependency, time.Now()) | ||
Expect(buffer.String()).To(Equal(" Selected Some Dependency 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: "Some Dependency", | ||
Version: "some-version", | ||
} | ||
|
||
emitter.SelectedDependency(packit.BuildpackPlanEntry{}, dependency, time.Now()) | ||
Expect(buffer.String()).To(Equal(" Selected Some Dependency 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: "Some Dependency", | ||
Version: "some-version", | ||
} | ||
|
||
emitter.SelectedDependency(entry, dependency, now) | ||
Expect(buffer.String()).To(ContainSubstring(" Selected Some Dependency version (using some-source): some-version\n")) | ||
Expect(buffer.String()).To(ContainSubstring(" Version some-version of Some Dependency will be deprecated after 2021-04-01.\n")) | ||
Expect(buffer.String()).To(ContainSubstring(" Migrate your application to a supported version of Some Dependency 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: "Some Dependency", | ||
Version: "some-version", | ||
} | ||
|
||
emitter.SelectedDependency(entry, dependency, now) | ||
Expect(buffer.String()).To(ContainSubstring(" Selected Some Dependency version (using some-source): some-version\n")) | ||
Expect(buffer.String()).To(ContainSubstring(" Version some-version of Some Dependency is deprecated.\n")) | ||
Expect(buffer.String()).To(ContainSubstring(" Migrate your application to a supported version of Some Dependency.\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: "Some Dependency", | ||
Version: "some-version", | ||
} | ||
|
||
emitter.SelectedDependency(entry, dependency, now) | ||
Expect(buffer.String()).To(ContainSubstring(" Selected Some Dependency version (using some-source): some-version\n")) | ||
Expect(buffer.String()).To(ContainSubstring(" Version some-version of Some Dependency is deprecated.\n")) | ||
Expect(buffer.String()).To(ContainSubstring(" Migrate your application to a supported version of Some Dependency.\n\n")) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters