Skip to content

Commit

Permalink
Add missing test files
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmachado committed Jan 8, 2020
1 parent f7eed22 commit ef55ee9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
56 changes: 56 additions & 0 deletions cmd/show_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import (
"bytes"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
)

func TestShowCmd(t *testing.T) {
changelog, err := ioutil.ReadFile("testdata/show-changelog.md")
if err != nil {
t.Fatal(err)
}

expected := `### Added
- Item 1
- Item 2
### Changed
- Item 3
`

out := new(bytes.Buffer)
iostreams := &IOStreams{
In: bytes.NewBuffer(changelog),
Out: out,
}

cmd := newShowCmd(iostreams)
cmd.SetArgs([]string{"1.0.0"})
_, err = cmd.ExecuteC()

assert.Nil(t, err)
assert.Equal(t, expected, string(out.Bytes()))
}

func TestShowCmdUnknownVersion(t *testing.T) {
changelog, err := ioutil.ReadFile("testdata/show-changelog.md")
if err != nil {
t.Fatal(err)
}

out := new(bytes.Buffer)
iostreams := &IOStreams{
In: bytes.NewBuffer(changelog),
Out: out,
}

cmd := newShowCmd(iostreams)
cmd.SetArgs([]string{"9.9.9"})
_, err = cmd.ExecuteC()

assert.NotNil(t, err)
}
21 changes: 21 additions & 0 deletions cmd/testdata/show-changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Removed
- Item 4

## [1.0.0] - 2020-01-08
### Added
- Item 1
- Item 2

### Changed
- Item 3

[Unreleased]: https://github.com/rcmachado/changelog/compare/1.0.0...HEAD
[1.0.0]: https://github.com/rcmachado/changelog/compare/ae761ff...1.0.0

0 comments on commit ef55ee9

Please sign in to comment.