Skip to content

Commit

Permalink
test postgres json column
Browse files Browse the repository at this point in the history
  • Loading branch information
gavincabbage committed Oct 1, 2019
1 parent de250aa commit 7869254
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Install dependencies
run: go mod download
- name: Run unit tests
run: go test -v -p 1 -tags=unit -covermode=atomic -timeout=30s ./...
run: go test -v -p 1 -tags=unit -timeout=30s ./...

benchmark:
name: Benchmark
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- name: Install dependencies
run: go mod download
- name: Run integration tests
run: go test -v -p 1 -tags=integration -covermode=atomic -timeout=60s ./...
run: go test -v -p 1 -tags=integration -timeout=60s ./...
env:
AWS_ACCESS_KEY_ID: bogus
AWS_SECRET_KEY: bogus
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---

<p align="center">
Archive relational database tables to Amazon S3.
Archive relational data to Amazon S3.
</p>

<div align="center">
Expand Down
30 changes: 20 additions & 10 deletions chiv_formatters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,63 @@ var cases = []testCase{
name: "second_column",
databaseType: "TEXT",
},
{
name: "third_column",
databaseType: "FLOAT",
},
},
records: [][][]byte{
{
[]byte("1"),
[]byte("first_row"),
[]byte("100"),
},
{
[]byte("2"),
[]byte("second_row"),
[]byte("12.12"),
},
{
[]byte("3"),
[]byte("third_row"),
[]byte("42.42"),
},
},
},
}

func TestCsvFormatter(t *testing.T) {
expected := []string{
`first_column,second_column
1,first_row
2,second_row
3,third_row
expected := []string{`
first_column,second_column,third_column
1,first_row,100
2,second_row,12.12
3,third_row,42.42
`,
}

test(t, expected, chiv.CSV)
}

func TestYamlFormatter(t *testing.T) {
expected := []string{
`- first_column: 1
expected := []string{`
- first_column: 1
second_column: first_row
third_column: 100
- first_column: 2
second_column: second_row
third_column: 12.12
- first_column: 3
second_column: third_row
third_column: 42.42
`,
}

test(t, expected, chiv.YAML)
}

func TestJsonFormatter(t *testing.T) {
expected := []string{
`[{"first_column":1,"second_column":"first_row"},{"first_column":2,"second_column":"second_row"},{"first_column":3,"second_column":"third_row"}]`,
expected := []string{`
[{"first_column":1,"second_column":"first_row","third_column":100},{"first_column":2,"second_column":"second_row","third_column":12.12},{"first_column":3,"second_column":"third_row","third_column":42.42}]`,
}

test(t, expected, chiv.JSON)
Expand All @@ -100,7 +110,7 @@ func test(t *testing.T, expected []string, format chiv.FormatterFunc) {
}

assert.NoError(t, subject.Close())
assert.Equal(t, expected[i], b.String())
assert.Equal(t, expected[i][1:], b.String())
})
}
}
Expand Down
17 changes: 0 additions & 17 deletions chiv_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ func TestArchiver_Archive(t *testing.T) {
options []chiv.Option
calls []call
}{
{
name: "happy path csv",
driver: "postgres",
database: os.Getenv("POSTGRES_URL"),
setup: "./testdata/postgres/postgres_setup.sql",
teardown: "./testdata/postgres/postgres_teardown.sql",
bucket: "test_bucket",
options: []chiv.Option{},
calls: []call{
{
expected: "./testdata/postgres/postgres.csv",
table: "postgres_table",
key: "postgres_table",
options: []chiv.Option{},
},
},
},
{
name: "postgres to csv",
driver: "postgres",
Expand Down
8 changes: 4 additions & 4 deletions testdata/postgres/postgres.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,text_column,char_column,int_column,float_column,bool_column,ts_column
ea09d13c-f441-4550-9492-115f8b409c96,some text,some chars,42,3.14,true,2018-01-04T00:00:00Z
4289a9e3-32d5-4bad-b79b-034c528e8f41,some other text,,100,3.141592,true,2018-02-04T00:00:00Z
7530a381-526a-42aa-a9ba-97fb2bca283f,some more text,some more chars,101,,false,2018-02-05T00:00:00Z
id,text_column,char_column,int_column,float_column,bool_column,ts_column,json_column
ea09d13c-f441-4550-9492-115f8b409c96,some text,some chars,42,3.14,true,2018-01-04T00:00:00Z,"{""key"":""value"",""num"":42}"
4289a9e3-32d5-4bad-b79b-034c528e8f41,some other text,,100,3.141592,true,2018-02-04T00:00:00Z,"{""other"":""value""}"
7530a381-526a-42aa-a9ba-97fb2bca283f,some more text,some more chars,101,,false,2018-02-05T00:00:00Z,"[{""item"":""in an array""},{""num"":999}]"
2 changes: 1 addition & 1 deletion testdata/postgres/postgres.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"bool_column":true,"char_column":"some chars","float_column":3.14,"id":"ea09d13c-f441-4550-9492-115f8b409c96","int_column":42,"text_column":"some text","ts_column":"2018-01-04T00:00:00Z"},{"bool_column":true,"char_column":null,"float_column":3.141592,"id":"4289a9e3-32d5-4bad-b79b-034c528e8f41","int_column":100,"text_column":"some other text","ts_column":"2018-02-04T00:00:00Z"},{"bool_column":false,"char_column":"some more chars","float_column":null,"id":"7530a381-526a-42aa-a9ba-97fb2bca283f","int_column":101,"text_column":"some more text","ts_column":"2018-02-05T00:00:00Z"}]
[{"bool_column":true,"char_column":"some chars","float_column":3.14,"id":"ea09d13c-f441-4550-9492-115f8b409c96","int_column":42,"json_column":"{\"key\":\"value\",\"num\":42}","text_column":"some text","ts_column":"2018-01-04T00:00:00Z"},{"bool_column":true,"char_column":null,"float_column":3.141592,"id":"4289a9e3-32d5-4bad-b79b-034c528e8f41","int_column":100,"json_column":"{\"other\":\"value\"}","text_column":"some other text","ts_column":"2018-02-04T00:00:00Z"},{"bool_column":false,"char_column":"some more chars","float_column":null,"id":"7530a381-526a-42aa-a9ba-97fb2bca283f","int_column":101,"json_column":"[{\"item\":\"in an array\"},{\"num\":999}]","text_column":"some more text","ts_column":"2018-02-05T00:00:00Z"}]
3 changes: 3 additions & 0 deletions testdata/postgres/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
float_column: 3.14
id: ea09d13c-f441-4550-9492-115f8b409c96
int_column: 42
json_column: '{"key":"value","num":42}'
text_column: some text
ts_column: "2018-01-04T00:00:00Z"
- bool_column: true
char_column: null
float_column: 3.141592
id: 4289a9e3-32d5-4bad-b79b-034c528e8f41
int_column: 100
json_column: '{"other":"value"}'
text_column: some other text
ts_column: "2018-02-04T00:00:00Z"
- bool_column: false
char_column: some more chars
float_column: null
id: 7530a381-526a-42aa-a9ba-97fb2bca283f
int_column: 101
json_column: '[{"item":"in an array"},{"num":999}]'
text_column: some more text
ts_column: "2018-02-05T00:00:00Z"
12 changes: 8 additions & 4 deletions testdata/postgres/postgres_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ CREATE TABLE IF NOT EXISTS postgres_table (
int_column INTEGER,
float_column NUMERIC,
bool_column BOOLEAN,
ts_column TIMESTAMP
ts_column TIMESTAMP,
json_column JSON
);

INSERT INTO postgres_table VALUES (
Expand All @@ -15,7 +16,8 @@ INSERT INTO postgres_table VALUES (
42,
3.14,
true,
'2018-01-04'::timestamp
'2018-01-04'::timestamp,
'{"key":"value","num":42}'
);

INSERT INTO postgres_table VALUES (
Expand All @@ -25,7 +27,8 @@ INSERT INTO postgres_table VALUES (
100,
3.141592,
true,
'2018-02-04'::timestamp
'2018-02-04'::timestamp,
'{"other":"value"}'
);

INSERT INTO postgres_table VALUES (
Expand All @@ -35,5 +38,6 @@ INSERT INTO postgres_table VALUES (
101,
null,
false,
'2018-02-05'::timestamp
'2018-02-05'::timestamp,
'[{"item":"in an array"},{"num":999}]'
);
8 changes: 4 additions & 4 deletions testdata/postgres/postgres_with_null.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,text_column,char_column,int_column,float_column,bool_column,ts_column
ea09d13c-f441-4550-9492-115f8b409c96,some text,some chars,42,3.14,true,2018-01-04T00:00:00Z
4289a9e3-32d5-4bad-b79b-034c528e8f41,some other text,custom_null,100,3.141592,true,2018-02-04T00:00:00Z
7530a381-526a-42aa-a9ba-97fb2bca283f,some more text,some more chars,101,custom_null,false,2018-02-05T00:00:00Z
id,text_column,char_column,int_column,float_column,bool_column,ts_column,json_column
ea09d13c-f441-4550-9492-115f8b409c96,some text,some chars,42,3.14,true,2018-01-04T00:00:00Z,"{""key"":""value"",""num"":42}"
4289a9e3-32d5-4bad-b79b-034c528e8f41,some other text,custom_null,100,3.141592,true,2018-02-04T00:00:00Z,"{""other"":""value""}"
7530a381-526a-42aa-a9ba-97fb2bca283f,some more text,some more chars,101,custom_null,false,2018-02-05T00:00:00Z,"[{""item"":""in an array""},{""num"":999}]"

0 comments on commit 7869254

Please sign in to comment.