Skip to content

Commit

Permalink
Adds formatting for digests and IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
thitch97 authored and ryanmoran committed Aug 13, 2020
1 parent 2138111 commit 2a1fca2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
12 changes: 6 additions & 6 deletions cargo/jam/internal/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -142,15 +142,15 @@ func (f Formatter) Markdown(configs []cargo.Config) {

for _, config := range configs {
fmt.Fprintf(f.writer, "\n<details>\n<summary>%s %s</summary>\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</details>\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])
}

Expand Down
50 changes: 29 additions & 21 deletions cargo/jam/internal/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -286,29 +294,29 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) {
---
<details>
<summary>Some Buildpack 1.2.3</summary>
<summary>Some Buildpack 1.2.3</summary>` +

**ID:** some-buildpack
"\n\n**ID:** `some-buildpack`\n\n" +

---
`---
</details>
<details>
<summary>Optional Buildpack 2.3.4</summary>
<summary>Optional Buildpack 2.3.4</summary>` +

**ID:** optional-buildpack
"\n\n**ID:** `optional-buildpack`\n\n" +

---
`---
</details>
<details>
<summary>Other Buildpack 3.4.5</summary>
<summary>Other Buildpack 3.4.5</summary>` +

**ID:** other-buildpack
"\n\n**ID:** `other-buildpack`\n\n" +

---
`---
</details>
`))
Expand Down
19 changes: 10 additions & 9 deletions cargo/jam/summarize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -270,11 +271,11 @@ version = "3.4.5"
---
<details>
<summary>Some Buildpack 1.2.3</summary>
<summary>Some Buildpack 1.2.3</summary>` +

**ID:** some-buildpack
"\n\n**ID:** `some-buildpack`\n\n" +

#### Supported Stacks:
`#### Supported Stacks:
- other-stack
- some-stack
Expand All @@ -295,11 +296,11 @@ version = "3.4.5"
</details>
<details>
<summary>Other Buildpack 2.3.4</summary>
<summary>Other Buildpack 2.3.4</summary>` +

**ID:** other-buildpack
"\n\n**ID:** `other-buildpack`\n\n" +

#### Supported Stacks:
`#### Supported Stacks:
- first-stack
- second-stack
Expand Down

0 comments on commit 2a1fca2

Please sign in to comment.