-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from harakeishi/add_test_and_comment
Add test and comment
- Loading branch information
Showing
13 changed files
with
429 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.20.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package trv | ||
|
||
import "strings" | ||
|
||
type schema string | ||
|
||
// Parses schema information output in markdown from tbls | ||
func (s schema) parse() (Description string, columns []Column) { | ||
tmp := strings.Split(string(s), "#") | ||
d := strings.Split(tmp[3], "\n") | ||
Description = d[2] | ||
|
||
var columIndex int | ||
tmp = strings.Split(string(s), "#") | ||
for i, v := range tmp { | ||
if strings.Contains(v, "Columns") { | ||
columIndex = i | ||
} | ||
} | ||
|
||
rows := strings.Split(tmp[columIndex], "\n") | ||
header := strings.Split(rows[2], "|") | ||
nameIndex := index(header, "Name") | ||
typeIndex := index(header, "Type") | ||
commentIndex := index(header, "Comment") | ||
|
||
for i, v := range rows { | ||
if i < 4 { | ||
continue | ||
} | ||
colum := strings.Split(v, "|") | ||
if len(colum) < 8 { | ||
return | ||
} | ||
columns = append(columns, Column{ | ||
Name: strings.TrimSpace(colum[nameIndex]), | ||
Type: strings.TrimSpace(colum[typeIndex]), | ||
Comment: strings.TrimSpace(colum[commentIndex]), | ||
}) | ||
} | ||
return | ||
} | ||
|
||
func index(a []string, query string) int { | ||
for i, v := range a { | ||
if strings.TrimSpace(v) == query { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package trv | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_schema_parse(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
s schema | ||
wantDescription string | ||
wantColumns []Column | ||
}{ | ||
{ | ||
name: "", | ||
s: ` | ||
# users | ||
## Description | ||
ユーザーを管理するテーブル | ||
## Columns | ||
| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment | Labels | | ||
| ---- | ---- | ------- | -------- | ---------------- | -------- | ------- | ------- | ------ | | ||
| id | int | | false | auto_increment | [comment_stars](comment_stars.md) [comments](comments.md) [posts](posts.md) [user_options](user_options.md) [logs](logs.md) | | ユーザーID | | | ||
## Constraints | ||
| Name | Type | Definition | | ||
| ---- | ---- | ---------- | | ||
| email | UNIQUE | UNIQUE KEY email (email) | | ||
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) | | ||
| username | UNIQUE | UNIQUE KEY username (username) | | ||
## Indexes | ||
| Name | Definition | | ||
| ---- | ---------- | | ||
| PRIMARY | PRIMARY KEY (id) USING BTREE | | ||
| email | UNIQUE KEY email (email) USING BTREE | | ||
| username | UNIQUE KEY username (username) USING BTREE | | ||
## Relations | ||
![er](users.svg) | ||
--- | ||
> Generated by [tbls](https://github.com/k1LoW/tbls) | ||
`, | ||
wantDescription: "ユーザーを管理するテーブル", | ||
wantColumns: []Column{ | ||
{ | ||
Name: "id", | ||
Type: "int", | ||
Comment: "ユーザーID", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotDescription, gotColumns := tt.s.parse() | ||
if gotDescription != tt.wantDescription { | ||
t.Errorf("schema.parse() gotDescription = %v, want %v", gotDescription, tt.wantDescription) | ||
} | ||
if !reflect.DeepEqual(gotColumns, tt.wantColumns) { | ||
t.Errorf("schema.parse() gotColumns = %v, want %v", gotColumns, tt.wantColumns) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.