From 2a1fca2b76051da33ac96130e0e5bb09d01c2baa Mon Sep 17 00:00:00 2001 From: Tim Hitchener Date: Thu, 13 Aug 2020 11:05:42 -0400 Subject: [PATCH] Adds formatting for digests and IDs --- cargo/jam/internal/formatter.go | 12 +++---- cargo/jam/internal/formatter_test.go | 50 ++++++++++++++++------------ cargo/jam/summarize_test.go | 19 ++++++----- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/cargo/jam/internal/formatter.go b/cargo/jam/internal/formatter.go index c23c3ae7..2cf74f74 100644 --- a/cargo/jam/internal/formatter.go +++ b/cargo/jam/internal/formatter.go @@ -122,8 +122,8 @@ func (f Formatter) Markdown(configs []cargo.Config) { //Language-family case if (familyConfig.Buildpack != cargo.ConfigBuildpack{}) { //Header section - fmt.Fprintf(f.writer, "# %s %s\n\n**ID:** %s\n\n", familyConfig.Buildpack.Name, familyConfig.Buildpack.Version, familyConfig.Buildpack.ID) - fmt.Fprintf(f.writer, "**Digest:** %s\n\n", familyConfig.Buildpack.SHA256) + fmt.Fprintf(f.writer, "## %s %s\n\n**ID:** `%s`\n\n", familyConfig.Buildpack.Name, familyConfig.Buildpack.Version, familyConfig.Buildpack.ID) + fmt.Fprintf(f.writer, "**Digest:** `%s`\n\n", familyConfig.Buildpack.SHA256) fmt.Fprintf(f.writer, "#### Included Buildpackages:\n") fmt.Fprintf(f.writer, "| Name | ID | Version |\n|---|---|---|\n") for _, config := range configs { @@ -142,15 +142,15 @@ func (f Formatter) Markdown(configs []cargo.Config) { for _, config := range configs { fmt.Fprintf(f.writer, "\n
\n%s %s\n", config.Buildpack.Name, config.Buildpack.Version) - fmt.Fprintf(f.writer, "\n**ID:** %s\n\n", config.Buildpack.ID) + fmt.Fprintf(f.writer, "\n**ID:** `%s`\n\n", config.Buildpack.ID) printImplementation(f.writer, config) fmt.Fprintf(f.writer, "---\n\n
\n") } } else { //Implementation case - fmt.Fprintf(f.writer, "# %s %s\n", configs[0].Buildpack.Name, configs[0].Buildpack.Version) - fmt.Fprintf(f.writer, "\n**ID:** %s\n\n", configs[0].Buildpack.ID) - fmt.Fprintf(f.writer, "**Digest:** %s\n\n", configs[0].Buildpack.SHA256) + fmt.Fprintf(f.writer, "## %s %s\n", configs[0].Buildpack.Name, configs[0].Buildpack.Version) + fmt.Fprintf(f.writer, "\n**ID:** `%s`\n\n", configs[0].Buildpack.ID) + fmt.Fprintf(f.writer, "**Digest:** `%s`\n\n", configs[0].Buildpack.SHA256) printImplementation(f.writer, configs[0]) } diff --git a/cargo/jam/internal/formatter_test.go b/cargo/jam/internal/formatter_test.go index e6c62983..d13d8525 100644 --- a/cargo/jam/internal/formatter_test.go +++ b/cargo/jam/internal/formatter_test.go @@ -72,11 +72,13 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) { }, }, }) - Expect(buffer.String()).To(Equal(`# Some Buildpack some-version + Expect(buffer.String()).To(Equal(`## Some Buildpack some-version` + -**ID:** some-buildpack + "\n\n**ID:** `some-buildpack`\n\n" + -**Digest:** sha256:some-buildpack-sha + "**Digest:** `sha256:some-buildpack-sha`" + + + ` #### Supported Stacks: - other-stack @@ -114,11 +116,13 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) { }, }, }) - Expect(buffer.String()).To(Equal(`# Some Buildpack some-version + Expect(buffer.String()).To(Equal(`## Some Buildpack some-version` + + + "\n\n**ID:** `some-buildpack`\n\n" + -**ID:** some-buildpack + "**Digest:** `sha256:some-buildpack-sha`" + -**Digest:** sha256:some-buildpack-sha + ` #### Supported Stacks: - other-stack @@ -172,11 +176,13 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) { }, }, }) - Expect(buffer.String()).To(Equal(`# Some Buildpack some-version + Expect(buffer.String()).To(Equal(`## Some Buildpack some-version` + -**ID:** some-buildpack + "\n\n**ID:** `some-buildpack`\n\n" + -**Digest:** sha256:some-buildpack-sha + "**Digest:** `sha256:some-buildpack-sha`" + + + ` #### Default Dependency Versions: | ID | Version | @@ -255,11 +261,13 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) { }, }, }) - Expect(buffer.String()).To(ContainSubstring(`# Order Buildpack order-version + Expect(buffer.String()).To(Equal(`## Order Buildpack order-version` + + + "\n\n**ID:** `order-buildpack`\n\n" + -**ID:** order-buildpack + "**Digest:** `sha256:order-buildpack-sha`" + -**Digest:** sha256:order-buildpack-sha + ` #### Included Buildpackages: | Name | ID | Version | @@ -286,29 +294,29 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) { ---
-Some Buildpack 1.2.3 +Some Buildpack 1.2.3` + -**ID:** some-buildpack + "\n\n**ID:** `some-buildpack`\n\n" + ---- + `---
-Optional Buildpack 2.3.4 +Optional Buildpack 2.3.4` + -**ID:** optional-buildpack + "\n\n**ID:** `optional-buildpack`\n\n" + ---- + `---
-Other Buildpack 3.4.5 +Other Buildpack 3.4.5` + -**ID:** other-buildpack + "\n\n**ID:** `other-buildpack`\n\n" + ---- + `---
`)) diff --git a/cargo/jam/summarize_test.go b/cargo/jam/summarize_test.go index b1736836..333ddc2a 100644 --- a/cargo/jam/summarize_test.go +++ b/cargo/jam/summarize_test.go @@ -245,11 +245,12 @@ version = "3.4.5" Expect(err).NotTo(HaveOccurred()) Eventually(session).Should(gexec.Exit(0), func() string { return buffer.String() }) - Expect(string(session.Out.Contents())).To(Equal(`# Meta Buildpack 3.4.5 + Expect(string(session.Out.Contents())).To(Equal(`## Meta Buildpack 3.4.5` + -**ID:** meta-buildpack + "\n\n**ID:** `meta-buildpack`\n\n" + -**Digest:** sha256:manifest-sha + "**Digest:** `sha256:manifest-sha`" + + ` #### Included Buildpackages: | Name | ID | Version | @@ -270,11 +271,11 @@ version = "3.4.5" ---
-Some Buildpack 1.2.3 +Some Buildpack 1.2.3` + -**ID:** some-buildpack + "\n\n**ID:** `some-buildpack`\n\n" + -#### Supported Stacks: + `#### Supported Stacks: - other-stack - some-stack @@ -295,11 +296,11 @@ version = "3.4.5"
-Other Buildpack 2.3.4 +Other Buildpack 2.3.4` + -**ID:** other-buildpack + "\n\n**ID:** `other-buildpack`\n\n" + -#### Supported Stacks: + `#### Supported Stacks: - first-stack - second-stack