-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
316 additions
and
92 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
## [](https://github.com/nao1215/sqly/compare/v0.6.5...) (2024-04-29) | ||
## [](https://github.com/nao1215/sqly/compare/v0.7.0...) (2024-04-30) | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,77 @@ | ||
package persistence | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/nao1215/sqly/domain/model" | ||
) | ||
|
||
func Test_excelRepository_List(t *testing.T) { | ||
t.Run("list excel data", func(t *testing.T) { | ||
r := NewExcelRepository() | ||
|
||
excel, err := r.List("testdata/sample.xlsx", "test_sheet") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := &model.Excel{ | ||
Name: "test_sheet", | ||
Header: model.Header{"id", "name"}, | ||
Records: []model.Record{ | ||
{"1", "Gina"}, | ||
{"2", "Yulia"}, | ||
{"3", "Vika"}, | ||
}, | ||
} | ||
|
||
if diff := cmp.Diff(excel, want); diff != "" { | ||
t.Fatalf("differs: (-got +want)\n%s", diff) | ||
} | ||
}) | ||
} | ||
|
||
func Test_excelRepository_Dump(t *testing.T) { | ||
t.Run("dump excel data", func(t *testing.T) { | ||
r := NewExcelRepository() | ||
|
||
excel := &model.Table{ | ||
Name: "test_sheet", | ||
Header: model.Header{"id", "name"}, | ||
Records: []model.Record{ | ||
{"1", "Gina"}, | ||
{"2", "Yulia"}, | ||
{"3", "Vika"}, | ||
{"4", "Hartlova"}, | ||
}, | ||
} | ||
|
||
tempFilePath := filepath.Join(os.TempDir(), "dump.xlsx") | ||
defer os.Remove(tempFilePath) // Clean up the temporary file after the test | ||
if err := r.Dump(tempFilePath, excel); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
got, err := r.List(tempFilePath, "test_sheet") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
want := &model.Excel{ | ||
Name: "test_sheet", | ||
Header: model.Header{"id", "name"}, | ||
Records: []model.Record{ | ||
{"1", "Gina"}, | ||
{"2", "Yulia"}, | ||
{"3", "Vika"}, | ||
{"4", "Hartlova"}, | ||
}, | ||
} | ||
|
||
if diff := cmp.Diff(got, want); diff != "" { | ||
t.Fatalf("differs: (-got +want)\n%s", diff) | ||
} | ||
}) | ||
} |
Binary file not shown.
Binary file not shown.
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 @@ | ||
not support data definition language: CREATE, DROP, ALTER, REINDEX |
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,153 @@ | ||
package usecase | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestSQLite3Interactor_ExecSQL(t *testing.T) { | ||
t.Run("execute CREATE error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)") | ||
|
||
want := "not support data definition language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute DROP error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "DROP TABLE test") | ||
|
||
want := "not support data definition language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute ALTER error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "ALTER TABLE test ADD COLUMN age INTEGER") | ||
|
||
want := "not support data definition language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute REINDEX error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "REINDEX test") | ||
|
||
want := "not support data definition language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute BEGIN error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "BEGIN") | ||
|
||
want := "not support transaction control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute COMMIT error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "COMMIT") | ||
|
||
want := "not support transaction control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute ROLLBACK error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "ROLLBACK") | ||
|
||
want := "not support transaction control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute SAVEPOINT error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "SAVEPOINT test") | ||
|
||
want := "not support transaction control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute RELEASE error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "RELEASE test") | ||
|
||
want := "not support transaction control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute GRANT error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "GRANT SELECT ON test TO user") | ||
|
||
want := "not support data control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute REVOKE error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "REVOKE SELECT ON test FROM user") | ||
|
||
want := "not support data control language" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
|
||
t.Run("execute undifined statement error", func(t *testing.T) { | ||
interactor := NewSQLite3Interactor(nil, nil) | ||
|
||
si := NewSQLite3Interactor(interactor, NewSQL()) | ||
_, _, got := si.ExecSQL(context.Background(), "UNDEFINED STATEMENT") | ||
|
||
want := "this input is not sql query or sqly helper command:" | ||
if !strings.Contains(got.Error(), want) { | ||
t.Errorf("want: %v, got: %v", want, got) | ||
} | ||
}) | ||
} |