Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mv test/ to testdata/ #61

Merged
merged 2 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ RELEASE_BUILD_LDFLAGS = -s -w $(BUILD_LDFLAGS)
default: test

test:
usql pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -f test/pg.sql
usql my://root:mypass@localhost:33306/testdb -f test/my.sql
usql my://root:mypass@localhost:33308/testdb -f test/my.sql
sqlite3 $(CURDIR)/test/testdb.sqlite3 < test/sqlite.sql
usql pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -f testdata/pg.sql
usql my://root:mypass@localhost:33306/testdb -f testdata/my.sql
usql my://root:mypass@localhost:33308/testdb -f testdata/my.sql
sqlite3 $(CURDIR)/testdata/testdb.sqlite3 < testdata/sqlite.sql
$(GO) test ./... -coverprofile=coverage.txt -covermode=count
make testdoc

doc: build
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml -f sample/postgres
./tbls doc my://root:mypass@localhost:33306/testdb -a test/additional_data.yml -f sample/mysql
./tbls doc my://root:mypass@localhost:33308/testdb -a test/additional_data.yml -f sample/mysql8
./tbls doc sq://$(CURDIR)/test/testdb.sqlite3 -a test/additional_data.yml -f sample/sqlite
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml -j -f sample/adjust
./tbls doc my://root:mypass@localhost:33306/testdb -a test/additional_data.yml -t svg -f sample/svg
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a testdata/additional_data.yml -f sample/postgres
./tbls doc my://root:mypass@localhost:33306/testdb -a testdata/additional_data.yml -f sample/mysql
./tbls doc my://root:mypass@localhost:33308/testdb -a testdata/additional_data.yml -f sample/mysql8
./tbls doc sq://$(CURDIR)/testdata/testdb.sqlite3 -a testdata/additional_data.yml -f sample/sqlite
./tbls doc pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a testdata/additional_data.yml -j -f sample/adjust
./tbls doc my://root:mypass@localhost:33306/testdb -a testdata/additional_data.yml -t svg -f sample/svg

testdoc: build
$(eval DIFF := $(shell ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml sample/postgres))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml sample/postgres && exit 1)
$(eval DIFF := $(shell ./tbls diff my://root:mypass@localhost:33306/testdb -a test/additional_data.yml sample/mysql))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff my://root:mypass@localhost:33306/testdb -a test/additional_data.yml sample/mysql && exit 1)
$(eval DIFF := $(shell ./tbls diff my://root:mypass@localhost:33308/testdb -a test/additional_data.yml sample/mysql8))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff my://root:mypass@localhost:33308/testdb -a test/additional_data.yml sample/mysql8 && exit 1)
$(eval DIFF := $(shell ./tbls diff sq://$(CURDIR)/test/testdb.sqlite3 -a test/additional_data.yml sample/sqlite))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff sq://$(CURDIR)/test/testdb.sqlite3 -a test/additional_data.yml sample/sqlite && exit 1)
$(eval DIFF := $(shell ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml -j sample/adjust))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a test/additional_data.yml -j sample/adjust && exit 1)
$(eval DIFF := $(shell ./tbls diff my://root:mypass@localhost:33306/testdb -a test/additional_data.yml -t svg sample/svg))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff my://root:mypass@localhost:33306/testdb -a test/additional_data.yml -t svg sample/svg && exit 1)
$(eval DIFF := $(shell ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a testdata/additional_data.yml sample/postgres))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a testdata/additional_data.yml sample/postgres && exit 1)
$(eval DIFF := $(shell ./tbls diff my://root:mypass@localhost:33306/testdb -a testdata/additional_data.yml sample/mysql))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff my://root:mypass@localhost:33306/testdb -a testdata/additional_data.yml sample/mysql && exit 1)
$(eval DIFF := $(shell ./tbls diff my://root:mypass@localhost:33308/testdb -a testdata/additional_data.yml sample/mysql8))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff my://root:mypass@localhost:33308/testdb -a testdata/additional_data.yml sample/mysql8 && exit 1)
$(eval DIFF := $(shell ./tbls diff sq://$(CURDIR)/testdata/testdb.sqlite3 -a testdata/additional_data.yml sample/sqlite))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff sq://$(CURDIR)/testdata/testdb.sqlite3 -a testdata/additional_data.yml sample/sqlite && exit 1)
$(eval DIFF := $(shell ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a testdata/additional_data.yml -j sample/adjust))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -a testdata/additional_data.yml -j sample/adjust && exit 1)
$(eval DIFF := $(shell ./tbls diff my://root:mypass@localhost:33306/testdb -a testdata/additional_data.yml -t svg sample/svg))
@test -z "$(DIFF)" || (echo "document does not match database." && ./tbls diff my://root:mypass@localhost:33306/testdb -a testdata/additional_data.yml -t svg sample/svg && exit 1)

test_too_many_tables: build
usql pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -f test/createdb_too_many.sql
usql pg://postgres:pgpass@localhost:55432/too_many?sslmode=disable -f test/createtable_too_many.sql
usql pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable -f testdata/createdb_too_many.sql
usql pg://postgres:pgpass@localhost:55432/too_many?sslmode=disable -f testdata/createtable_too_many.sql
ulimit -n 256 && ./tbls doc pg://postgres:pgpass@localhost:55432/too_many?sslmode=disable -f /tmp
ulimit -n 256 && ./tbls diff pg://postgres:pgpass@localhost:55432/too_many?sslmode=disable /tmp

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $ tbls doc postgres://user:pass@hostname:5432/dbname ./dbdoc

If you can use Graphviz `dot` command, `tbls doc` generate ER diagram images at the same time.

Sample [document](sample/postgres/) and [schema](test/pg.sql).
Sample [document](sample/postgres/) and [schema](testdata/pg.sql).

> NOTICE: If you are using a symbol such as `#` `<` in database password, URL-encode the password

Expand Down Expand Up @@ -82,7 +82,7 @@ testdoc: ## Test database schema document

## Add additional data (relations, comments) to schema

To add additional data to the schema, specify [the yaml file](test/additional_data.yml) with the `--add` option as follows
To add additional data to the schema, specify [the yaml file](testdata/additional_data.yml) with the `--add` option as follows

``` console
$ tbls diff mysql://user:pass@hostname:3306/dbname --add path/to/additional_data.yml ./dbdoc
Expand Down
7 changes: 4 additions & 3 deletions drivers/sqlite/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"os"
"testing"

"path/filepath"
"reflect"

"github.com/k1LoW/tbls/schema"
_ "github.com/mattn/go-sqlite3"
"github.com/xo/dburl"
"path/filepath"
"reflect"
)

var s *schema.Schema
Expand All @@ -21,7 +22,7 @@ func TestMain(m *testing.M) {
Name: "testdb.sqlite3",
}
dir, _ := os.Getwd()
sqliteFilepath, _ := filepath.Abs(filepath.Join(filepath.Dir(filepath.Dir(dir)), "test", "testdb.sqlite3"))
sqliteFilepath, _ := filepath.Abs(filepath.Join(filepath.Dir(filepath.Dir(dir)), "testdata", "testdb.sqlite3"))

db, _ = dburl.Open(fmt.Sprintf("sq://%s", sqliteFilepath))
defer db.Close()
Expand Down
63 changes: 15 additions & 48 deletions output/dot/dot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package dot

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/k1LoW/tbls/schema"
Expand All @@ -14,31 +17,10 @@ func TestOutputSchema(t *testing.T) {
if err != nil {
t.Error(err)
}
expected := `digraph "testschema" {
// Config
graph [rankdir=TB, layout=dot, fontname="Arial"];
node [shape=record, fontsize=14, margin=0.6, fontname="Arial"];
edge [fontsize=10, labelfloat=false, splines=none, fontname="Arial"];

// Tables
"a" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">a</font> <font color="#666666">[]</font></td></tr>
<tr><td port="a" align="left">a <font color="#666666">[]</font></td></tr>
<tr><td port="a2" align="left">a2 <font color="#666666">[]</font></td></tr>
</table>>];
"b" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">b</font> <font color="#666666">[]</font></td></tr>
<tr><td port="b" align="left">b <font color="#666666">[]</font></td></tr>
<tr><td port="b2" align="left">b2 <font color="#666666">[]</font></td></tr>
</table>>];

// Relations
"a":a -> "b":b [dir=back, arrowtail=crow, taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td></td></tr></table>>];
}
`
expected, _ := ioutil.ReadFile(filepath.Join(testdataDir(), "dot_test_schema.dot.golden"))
actual := buf.String()
if actual != expected {
t.Errorf("actual %v\nwant %v", actual, expected)
if actual != string(expected) {
t.Errorf("actual %v\nwant %v", actual, string(expected))
}
}

Expand All @@ -48,34 +30,19 @@ func TestOutputTable(t *testing.T) {

buf := &bytes.Buffer{}
_ = OutputTable(buf, ta)
expected := `digraph "a" {
// Config
graph [rankdir=TB, layout=dot, fontname="Arial"];
node [shape=record, fontsize=14, margin=0.6, fontname="Arial"];
edge [fontsize=10, labelfloat=false, splines=none, fontname="Arial"];

// Tables
"a" [shape=none, label=<<table border="3" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">a</font> <font color="#666666">[]</font></td></tr>
<tr><td port="a" align="left">a <font color="#666666">[]</font></td></tr>
<tr><td port="a2" align="left">a2 <font color="#666666">[]</font></td></tr>
</table>>];
"b" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">b</font> <font color="#666666">[]</font></td></tr>
<tr><td port="b" align="left">b <font color="#666666">[]</font></td></tr>
<tr><td port="b2" align="left">b2 <font color="#666666">[]</font></td></tr>
</table>>];

// Relations
"a":a -> "b":b [dir=back, arrowtail=crow, taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td></td></tr></table>>];
}
`
expected, _ := ioutil.ReadFile(filepath.Join(testdataDir(), "dot_test_a.dot.golden"))
actual := buf.String()
if actual != expected {
t.Errorf("actual %v\nwant %v", actual, expected)
if actual != string(expected) {
t.Errorf("actual %v\nwant %v", actual, string(expected))
}
}

func testdataDir() string {
wd, _ := os.Getwd()
dir, _ := filepath.Abs(filepath.Join(filepath.Dir(filepath.Dir(wd)), "testdata"))
return dir
}

func newTestSchema() *schema.Schema {
ca := &schema.Column{
Name: "a",
Expand Down
76 changes: 23 additions & 53 deletions output/md/md_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import (
"github.com/k1LoW/tbls/schema"
)

var tests = []struct {
name string
actualFile string
expectedFile string
}{
{"README.md", "README.md", "md_test_README.md.golden"},
{"a.md", "a.md", "md_test_a.md.golden"},
}

func TestOutput(t *testing.T) {
s := newTestSchema()
tempDir, _ := ioutil.TempDir("", "tbls")
Expand All @@ -21,61 +30,22 @@ func TestOutput(t *testing.T) {
if err != nil {
t.Error(err)
}
expected := `# testschema

## Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [a](a.md) | 2 | table a | |
| [b](b.md) | 2 | table b | |



---

> Generated by [tbls](https://github.com/k1LoW/tbls)`
content, err := ioutil.ReadFile(filepath.Join(tempDir, "README.md"))
if err != nil {
log.Fatal(err)
}
actual := string(content)
if actual != expected {
t.Errorf("actual %v\nwant %v", actual, expected)
for _, tt := range tests {
expected, _ := ioutil.ReadFile(filepath.Join(testdataDir(), tt.expectedFile))
actual, err := ioutil.ReadFile(filepath.Join(tempDir, tt.actualFile))
if err != nil {
log.Fatal(err)
}
if string(actual) != string(expected) {
t.Errorf("actual %v\nwant %v", string(actual), string(expected))
}
}
}

expected2 := `# a

## Description

table a

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| a | | | false | | [b](b.md) | column a |
| a2 | | | false | | | column a2 |









---

> Generated by [tbls](https://github.com/k1LoW/tbls)`
content2, err := ioutil.ReadFile(filepath.Join(tempDir, "a.md"))
if err != nil {
log.Fatal(err)
}
actual2 := string(content2)
if actual2 != expected2 {
t.Errorf("actual %v\nwant %v", actual2, expected2)
}
func testdataDir() string {
wd, _ := os.Getwd()
dir, _ := filepath.Abs(filepath.Join(filepath.Dir(filepath.Dir(wd)), "testdata"))
return dir
}

func newTestSchema() *schema.Schema {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions testdata/dot_test_a.dot.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
digraph "a" {
// Config
graph [rankdir=TB, layout=dot, fontname="Arial"];
node [shape=record, fontsize=14, margin=0.6, fontname="Arial"];
edge [fontsize=10, labelfloat=false, splines=none, fontname="Arial"];

// Tables
"a" [shape=none, label=<<table border="3" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">a</font> <font color="#666666">[]</font></td></tr>
<tr><td port="a" align="left">a <font color="#666666">[]</font></td></tr>
<tr><td port="a2" align="left">a2 <font color="#666666">[]</font></td></tr>
</table>>];
"b" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">b</font> <font color="#666666">[]</font></td></tr>
<tr><td port="b" align="left">b <font color="#666666">[]</font></td></tr>
<tr><td port="b2" align="left">b2 <font color="#666666">[]</font></td></tr>
</table>>];

// Relations
"a":a -> "b":b [dir=back, arrowtail=crow, taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td></td></tr></table>>];
}
21 changes: 21 additions & 0 deletions testdata/dot_test_schema.dot.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
digraph "testschema" {
// Config
graph [rankdir=TB, layout=dot, fontname="Arial"];
node [shape=record, fontsize=14, margin=0.6, fontname="Arial"];
edge [fontsize=10, labelfloat=false, splines=none, fontname="Arial"];

// Tables
"a" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">a</font> <font color="#666666">[]</font></td></tr>
<tr><td port="a" align="left">a <font color="#666666">[]</font></td></tr>
<tr><td port="a2" align="left">a2 <font color="#666666">[]</font></td></tr>
</table>>];
"b" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">b</font> <font color="#666666">[]</font></td></tr>
<tr><td port="b" align="left">b <font color="#666666">[]</font></td></tr>
<tr><td port="b2" align="left">b2 <font color="#666666">[]</font></td></tr>
</table>>];

// Relations
"a":a -> "b":b [dir=back, arrowtail=crow, taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td></td></tr></table>>];
}
14 changes: 14 additions & 0 deletions testdata/md_test_README.md.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# testschema

## Tables

| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [a](a.md) | 2 | table a | |
| [b](b.md) | 2 | table b | |



---

> Generated by [tbls](https://github.com/k1LoW/tbls)
24 changes: 24 additions & 0 deletions testdata/md_test_a.md.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# a

## Description

table a

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| a | | | false | | [b](b.md) | column a |
| a2 | | | false | | | column a2 |









---

> Generated by [tbls](https://github.com/k1LoW/tbls)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.