From d4604d30dee9ad10327387593cb16fd63ea58d9a Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Thu, 10 Jun 2021 19:00:21 -0500 Subject: [PATCH] :white_check_mark: Add SqlFormat tests --- internal/database/sqlformat/format_test.go | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 internal/database/sqlformat/format_test.go diff --git a/internal/database/sqlformat/format_test.go b/internal/database/sqlformat/format_test.go new file mode 100644 index 00000000..62775eed --- /dev/null +++ b/internal/database/sqlformat/format_test.go @@ -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) + } + } +}