Skip to content

Enhance testing for document package. #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/krel/cmd/changelog_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ const alphaReleaseExpectedContent = `## Changes by Kind

### Other (Cleanup or Flake)

- Update cri-tools to v1.17.0 ([#86305](https://github.com/kubernetes/kubernetes/pull/86305), [@saschagrunert](https://github.com/saschagrunert)) [SIG Cluster Lifecycle and Release]
- Kubeadm: remove the deprecated CoreDNS feature-gate. It was set to "true" since v1.11 when the feature went GA. In v1.13 it was marked as deprecated and hidden from the CLI. ([#87400](https://github.com/kubernetes/kubernetes/pull/87400), [@neolit123](https://github.com/neolit123)) [SIG Cluster Lifecycle]
- Removed the 'client' label from apiserver_request_total. ([#87669](https://github.com/kubernetes/kubernetes/pull/87669), [@logicalhan](https://github.com/logicalhan)) [SIG API Machinery and Instrumentation]
- The CSR signing cert/key pairs will be reloaded from disk like the kube-apiserver cert/key pairs ([#86816](https://github.com/kubernetes/kubernetes/pull/86816), [@deads2k](https://github.com/deads2k)) [SIG API Machinery, Apps and Auth]`
- The CSR signing cert/key pairs will be reloaded from disk like the kube-apiserver cert/key pairs ([#86816](https://github.com/kubernetes/kubernetes/pull/86816), [@deads2k](https://github.com/deads2k)) [SIG API Machinery, Apps and Auth]
- Update cri-tools to v1.17.0 ([#86305](https://github.com/kubernetes/kubernetes/pull/86305), [@saschagrunert](https://github.com/saschagrunert)) [SIG Cluster Lifecycle and Release]`

const alphaReleaseExpectedHTMLHead = `<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -265,10 +265,10 @@ const alphaReleaseExpectedHTMLBottom = `
</ul>
<h3>Other (Cleanup or Flake)</h3>
<ul>
<li>Update cri-tools to v1.17.0 (<a href="https://github.com/kubernetes/kubernetes/pull/86305">#86305</a>, <a href="https://github.com/saschagrunert">@saschagrunert</a>) [SIG Cluster Lifecycle and Release]</li>
<li>Kubeadm: remove the deprecated CoreDNS feature-gate. It was set to &quot;true&quot; since v1.11 when the feature went GA. In v1.13 it was marked as deprecated and hidden from the CLI. (<a href="https://github.com/kubernetes/kubernetes/pull/87400">#87400</a>, <a href="https://github.com/neolit123">@neolit123</a>) [SIG Cluster Lifecycle]</li>
<li>Removed the 'client' label from apiserver_request_total. (<a href="https://github.com/kubernetes/kubernetes/pull/87669">#87669</a>, <a href="https://github.com/logicalhan">@logicalhan</a>) [SIG API Machinery and Instrumentation]</li>
<li>The CSR signing cert/key pairs will be reloaded from disk like the kube-apiserver cert/key pairs (<a href="https://github.com/kubernetes/kubernetes/pull/86816">#86816</a>, <a href="https://github.com/deads2k">@deads2k</a>) [SIG API Machinery, Apps and Auth]</li>
<li>Update cri-tools to v1.17.0 (<a href="https://github.com/kubernetes/kubernetes/pull/86305">#86305</a>, <a href="https://github.com/saschagrunert">@saschagrunert</a>) [SIG Cluster Lifecycle and Release]</li>
<li><code>(*&quot;k8s.io/client-go/rest&quot;.Request).{Do,DoRaw,Stream,Watch}</code> now require callers to pass a <code>context.Context</code> as an argument. The context is used for timeout and cancellation signaling and to pass supplementary information to round trippers in the wrapped transport chain. If you don't need any of this functionality, it is sufficient to pass a context created with <code>context.Background()</code> to these functions. The <code>(*&quot;k8s.io/client-go/rest&quot;.Request).Context</code> method is removed now that all methods that execute a request accept a context directly. (<a href="https://github.com/kubernetes/kubernetes/pull/87597">#87597</a>, <a href="https://github.com/mikedanese">@mikedanese</a>) [SIG API Machinery, Apps, Auth, Autoscaling, CLI, Cloud Provider, Cluster Lifecycle, Instrumentation, Network, Node, Scheduling, Storage and Testing]</li>
</ul>

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/golangci/golangci-lint v1.23.3
github.com/google/go-github/v29 v29.0.3
github.com/google/uuid v1.1.1
github.com/kylelemons/godebug v1.1.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481
github.com/olekukonko/tablewriter v0.0.4
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
Expand Down
2 changes: 1 addition & 1 deletion pkg/notes/document/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ go_test(
data = [":testdata"],
embed = [":go_default_library"],
deps = [
"//pkg/notes:go_default_library",
"//pkg/notes/options:go_default_library",
"//pkg/release:go_default_library",
"@com_github_kylelemons_godebug//diff:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
Expand Down
56 changes: 20 additions & 36 deletions pkg/notes/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -158,10 +159,12 @@ func (n *NoteCollection) Sort(kindPriority []Kind) {
})
}

// TODO: These should probably go into the notes package.
type Kind string
type NotesByKind map[Kind]Notes
type Notes []string

// TODO: These should probably go into the notes package.
const (
KindAPIChange Kind = "api-change"
KindBug Kind = "bug"
Expand All @@ -173,7 +176,6 @@ const (
KindFeature Kind = "feature"
KindFlake Kind = "flake"
KindRegression Kind = "regression"
// TODO: These should be same case as the others. Probably fix up prettyKind()??
KindOther Kind = "Other (Cleanup or Flake)"
KindUncategorized Kind = "Uncategorized"
)
Expand Down Expand Up @@ -207,6 +209,13 @@ func CreateDocument(releaseNotes notes.ReleaseNotes, history notes.ReleaseNotesH
Notes: NoteCollection{},
}

stripRE := regexp.MustCompile(`^([-\*]+\s+)`)
// processNote encapsulates the pre-processing that might happen on a note
// text before it gets bulleted during rendering.
processNote := func(s string) string {
return stripRE.ReplaceAllLiteralString(s, "")
}

kindCategory := make(map[Kind]NoteCategory)
for _, pr := range history {
note := releaseNotes[pr]
Expand All @@ -215,38 +224,38 @@ func CreateDocument(releaseNotes notes.ReleaseNotes, history notes.ReleaseNotesH
if note.DuplicateKind {
kind := mapKind(highestPriorityKind(note.Kinds))
if existing, ok := kindCategory[kind]; ok {
*existing.NoteEntries = append(*existing.NoteEntries, note.Markdown)
*existing.NoteEntries = append(*existing.NoteEntries, processNote(note.Markdown))
} else {
kindCategory[kind] = NoteCategory{Kind: kind, NoteEntries: &Notes{note.Markdown}}
kindCategory[kind] = NoteCategory{Kind: kind, NoteEntries: &Notes{processNote(note.Markdown)}}
}
} else if note.ActionRequired {
doc.NotesWithActionRequired = append(doc.NotesWithActionRequired, note.Markdown)
doc.NotesWithActionRequired = append(doc.NotesWithActionRequired, processNote(note.Markdown))
} else {
for _, kind := range note.Kinds {
mappedKind := mapKind(Kind(kind))

if existing, ok := kindCategory[mappedKind]; ok {
*existing.NoteEntries = append(*existing.NoteEntries, note.Markdown)
*existing.NoteEntries = append(*existing.NoteEntries, processNote(note.Markdown))
} else {
kindCategory[mappedKind] = NoteCategory{Kind: mappedKind, NoteEntries: &Notes{note.Markdown}}
kindCategory[mappedKind] = NoteCategory{Kind: mappedKind, NoteEntries: &Notes{processNote(note.Markdown)}}
}
}

if len(note.Kinds) == 0 {
// the note has not been categorized so far
kind := KindUncategorized
if existing, ok := kindCategory[kind]; ok {
*existing.NoteEntries = append(*existing.NoteEntries, note.Markdown)
*existing.NoteEntries = append(*existing.NoteEntries, processNote(note.Markdown))
} else {
kindCategory[kind] = NoteCategory{Kind: kind, NoteEntries: &Notes{note.Markdown}}
kindCategory[kind] = NoteCategory{Kind: kind, NoteEntries: &Notes{processNote(note.Markdown)}}
}
}
}
}

for _, category := range kindCategory {
doc.Notes = append(doc.Notes, category)
sort.Strings(*category.NoteEntries)
doc.Notes = append(doc.Notes, category)
}

doc.Notes.Sort(kindPriority)
Expand Down Expand Up @@ -281,7 +290,7 @@ func (d *Document) RenderMarkdownTemplate(bucket, fileDir, templateSpec string)
if err := tmpl.Execute(&s, d); err != nil {
return "", errors.Wrapf(err, "rendering with template")
}
return s.String(), nil
return strings.TrimSpace(s.String()), nil
}

// template returns either the default template or a template from file. The
Expand Down Expand Up @@ -372,30 +381,6 @@ func (d *Document) RenderMarkdown(bucket, tars, prevTag, newTag string) (string,
return strings.TrimSpace(o.String()), nil
}

// sortKinds sorts kinds by their priority and returns the result in a string
// slice
func sortKinds(notesByKind NotesByKind) []Kind {
res := []Kind{}
for kind := range notesByKind {
res = append(res, kind)
}

indexOf := func(kind Kind) int {
for i, prioKind := range kindPriority {
if kind == prioKind {
return i
}
}
return -1
}

sort.Slice(res, func(i, j int) bool {
return indexOf(res[i]) < indexOf(res[j])
})

return res
}

// CreateDownloadsTable creates the markdown table with the links to the tarballs.
// The function does nothing if the `tars` variable is empty.
func CreateDownloadsTable(w io.Writer, bucket, tars, prevTag, newTag string) error {
Expand All @@ -408,8 +393,7 @@ func CreateDownloadsTable(w io.Writer, bucket, tars, prevTag, newTag string) err
if fileMetadata == nil {
// If directory is empty, doesn't contain matching files, or is not
// given we will have a nil value. This is not an error in every
// context. Return early so we do not modify markdown. This will be
// removed once issue #1019 lands.
// context. Return early so we do not modify markdown.
fmt.Fprintf(w, "# %s\n\n", newTag)
fmt.Fprintf(w, "## Changelog since %s\n\n", prevTag)
return nil
Expand Down
Loading