Skip to content

Commit

Permalink
テスト追加
Browse files Browse the repository at this point in the history
  • Loading branch information
harakeishi committed Feb 12, 2023
1 parent 5f6850a commit 4ca1a50
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions trv/table_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package trv

import (
"context"
"errors"
"reflect"
"testing"

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

type RepositoriesMock struct {
fileContent *github.RepositoryContent
err error
}

func (r RepositoriesMock) GetContents(ctx context.Context, owner string, repo string, path string, opt *github.RepositoryContentGetOptions) (fileContent *github.RepositoryContent, directoryContent []*github.RepositoryContent, resp *github.Response, err error) {
return r.fileContent, nil, nil, r.err
}

func TestTable_fetchTableInfoInMarkdownFromGitHub(t *testing.T) {
type args struct {
repositories Repositories
ctx context.Context
owner string
repo string
path string
}
ctx := context.Background()
name := "test"
content := "test content"
tests := []struct {
name string
tr *Table
args args
want schema
wantName string
wantErr bool
}{
{
name: "Correct table information can be retrieved.",
tr: &Table{},
args: args{
repositories: RepositoriesMock{
fileContent: &github.RepositoryContent{
Name: &name,
Content: &content,
},
err: nil,
},
ctx: ctx,
owner: "test",
repo: "test",
path: "test",
},
want: "test content",
wantName: "test",
wantErr: false,
},
{
name: "Ability to handle errors correctly",
tr: &Table{},
args: args{
repositories: RepositoriesMock{
fileContent: &github.RepositoryContent{},
err: errors.New("fail GetContents"),
},
ctx: ctx,
owner: "test",
repo: "test",
path: "test",
},
want: "",
wantName: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.tr.fetchTableInfoInMarkdownFromGitHub(tt.args.repositories, tt.args.ctx, tt.args.owner, tt.args.repo, tt.args.path)
if (err != nil) != tt.wantErr {
t.Errorf("Table.fetchTableInfoInMarkdownFromGitHub() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Table.fetchTableInfoInMarkdownFromGitHub() = %v, want %v", got, tt.want)
}
if tt.tr.Name != tt.wantName {
t.Errorf("Table.fetchTableInfoInMarkdownFromGitHub() = %v, want %v", tt.tr.Name, tt.wantName)
}
})
}
}

0 comments on commit 4ca1a50

Please sign in to comment.