Skip to content

Commit

Permalink
✅ Add SqlFormat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 11, 2021
1 parent b027664 commit d4604d3
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions internal/database/sqlformat/format_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package sqlformat

import "testing"

func TestParseFilename(t *testing.T) {
type filenameTestCase struct {
filename string
filetype uint8
error error
}

testCases := []filenameTestCase{
{filename: "dump.sql.gz", filetype: Gzip},
{filename: "dump.sql", filetype: Plain},
{filename: "dump.dmp", filetype: Custom},
{filename: "dump.png", filetype: Unknown, error: UnknownFormatError},
}
for key, testCase := range testCases {
filetype, err := ParseFilename(testCase.filename)
if err != testCase.error {
t.Error(err)
}
if filetype != testCase.filetype {
t.Errorf("case %d: got %v; expected %v", key, filetype, testCase.filetype)
}
}
}

func TestParseFormat(t *testing.T) {
type formatTestCase struct {
format string
filetype uint8
error error
}

testCases := []formatTestCase{
{format: "gzip", filetype: Gzip},
{format: "gz", filetype: Gzip},
{format: "g", filetype: Gzip},
{format: "plain", filetype: Plain},
{format: "sql", filetype: Plain},
{format: "p", filetype: Plain},
{format: "custom", filetype: Custom},
{format: "c", filetype: Custom},
{format: "png", filetype: Unknown, error: UnknownFormatError},
}
for key, testCase := range testCases {
format, err := ParseFormat(testCase.format)
if err != testCase.error {
t.Error(err)
}
if format != testCase.filetype {
t.Errorf("case %d: got %v; expected %v", key, format, testCase.filetype)
}
}
}

0 comments on commit d4604d3

Please sign in to comment.