Skip to content

Commit

Permalink
テストの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
harakeishi committed Feb 11, 2023
1 parent a324d34 commit 500b5e3
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on:
push:
branches:
- main
pull_request:
jobs:
golang-test:
strategy:
matrix:
go-version: [1.17.x]
os: [ubuntu-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
- name: testing
run: go test ./... -coverprofile=coverage.out
- name: create report
uses: k1LoW/octocov-action@v0
20 changes: 20 additions & 0 deletions .octocov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
coverage:
paths:
- coverage.out
codeToTestRatio:
code:
- '**/*.go'
- '!**/*_test.go'
test:
- '**/*_test.go'
testExecutionTime:
if: true
comment:
if: is_pull_request
report:
if: is_default_branch
datastores:
- artifact://${GITHUB_REPOSITORY}
diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ go 1.18

require (
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
github.com/google/go-cmp v0.5.2
github.com/google/go-github v17.0.0+incompatible
github.com/harakeishi/curver v0.1.2
github.com/mattn/go-runewidth v0.0.13
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8
github.com/spf13/cobra v1.4.0
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401
)

require (
github.com/gdamore/encoding v1.0.0 // indirect
github.com/genkiroid/cert v0.0.0-20191007122723-897560fbbe50 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 h1:QqwPZCwh/k1uYqq6uXSb9TRDhTkfQbO80v8zhnIe5zM=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
github.com/genkiroid/cert v0.0.0-20191007122723-897560fbbe50 h1:vLwmYBduhnWWqShoUGbVgDulhcLdanoYtCQxYMzwaqQ=
github.com/genkiroid/cert v0.0.0-20191007122723-897560fbbe50/go.mod h1:Pb7nyGYAfDyE/IkU6AJeRshIFko0wJC9cOqeYzYQffk=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down
91 changes: 91 additions & 0 deletions trv/config_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,92 @@
package trv

import (
"reflect"
"testing"

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

func TestConfig_getSourceList(t *testing.T) {
tests := []struct {
name string
c Config
want []string
}{
{
name: "The correct listing can be obtained from the source",
c: Config{
Source: []Source{
{
Repo: "test1",
Path: "testPath1",
},
{
Repo: "test2",
Path: "testPath2",
},
},
},
want: []string{
"test1/testPath1",
"test2/testPath2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.c.getSourceList(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Config.getSourceList() = %v, want %v", got, tt.want)
}
})
}
}

func TestConfig_addSource(t *testing.T) {
type args struct {
s Source
}
tests := []struct {
name string
c *Config
args args
want Config
}{
{
name: "Correct source is added.",
c: &Config{},
args: args{
s: Source{
Owner: "test",
Repo: "test",
Path: "test",
IsEnterprise: false,
Token: "test",
BaseURL: "",
UploadURL: "",
},
},
want: Config{
Source: []Source{
{
Owner: "test",
Repo: "test",
Path: "test",
IsEnterprise: false,
Token: "test",
BaseURL: "",
UploadURL: "",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.c.addSource(tt.args.s)
if diff := cmp.Diff(tt.c.Source, tt.want.Source); diff != "" {
t.Errorf("Source value is mismatch (-get +want):\n%s", diff)
}
})
}
}

0 comments on commit 500b5e3

Please sign in to comment.