Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Nov 8, 2021
1 parent 249f4cc commit b51d77a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.go-version
dist/
coverage.txt
coverage.out
/ghput
8 changes: 4 additions & 4 deletions gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ func (g *Gh) CreateRelease(ctx context.Context, tag, title, body string) error {

func unique(in []string) []string {
m := map[string]struct{}{}
u := []string{}
for _, s := range in {
if _, ok := m[s]; !ok {
u = append(u, s)
}
m[s] = struct{}{}
}
u := []string{}
for s := range m {
u = append(u, s)
}
return u
}
48 changes: 48 additions & 0 deletions gh/gh_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
package gh

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestMakeComment(t *testing.T) {
ctx := context.Background()
tests := []struct {
body string
header string
footer string
want string
}{
{"", "", "", "<!-- Put by ghput -->\n"},
{"body", "header", "footer", "header\nbody\nfooter\n<!-- Put by ghput -->\n"},
{"body\n", "header\n", "footer\n", "header\nbody\nfooter\n<!-- Put by ghput -->\n"},
}
for _, tt := range tests {
gh, err := New("o", "r", "")
if err != nil {
t.Fatal(err)
}
got, err := gh.MakeComment(ctx, tt.body, tt.header, tt.footer)
if err != nil {
t.Fatal(err)
}
if got != tt.want {
t.Errorf("got\n%v\nwant\n%v", got, tt.want)
}
}
}

func TestCommentFooter(t *testing.T) {
tests := []struct {
key string
Expand All @@ -30,3 +60,21 @@ func TestCommentFooter(t *testing.T) {
}
}
}

func TestUnique(t *testing.T) {
tests := []struct {
in []string
want []string
}{
{[]string{}, []string{}},
{[]string{"a", "c", "b"}, []string{"a", "c", "b"}},
{[]string{"b", "c", "b"}, []string{"b", "c"}},
{[]string{"a", "a", "b"}, []string{"a", "b"}},
}
for _, tt := range tests {
got := unique(tt.in)
if diff := cmp.Diff(got, tt.want, nil); diff != "" {
t.Errorf("%s", diff)
}
}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/k1LoW/ghput
go 1.17

require (
github.com/google/go-cmp v0.5.6
github.com/google/go-github/v39 v39.2.0
github.com/itchyny/timefmt-go v0.1.3
github.com/k1LoW/go-github-client/v39 v39.2.1
github.com/k1LoW/go-github-client/v39 v39.2.2
github.com/mattn/go-colorable v0.1.11
github.com/spf13/cobra v1.2.1
)
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/k1LoW/go-github-client/v39 v39.2.1 h1:JB+NKQ50pKV4fCbB5+vuD2KZRKaeEOyKe0FDqokJZ8A=
github.com/k1LoW/go-github-client/v39 v39.2.1/go.mod h1:fb0+5/ZUFspjDNIOqmzCb1s2KVI1UIOrDAQprhfhecY=
github.com/k1LoW/go-github-client/v39 v39.2.2 h1:BML9eBIvMnlM+u2awm8hugeaT//dd8ilR3sM5i/FzG8=
github.com/k1LoW/go-github-client/v39 v39.2.2/go.mod h1:fb0+5/ZUFspjDNIOqmzCb1s2KVI1UIOrDAQprhfhecY=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
Expand Down Expand Up @@ -471,6 +471,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Expand Down

0 comments on commit b51d77a

Please sign in to comment.