-
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.
[new] Write database and core file tests
- Loading branch information
1 parent
5ee3914
commit eef13d1
Showing
3 changed files
with
80 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package core_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/Firdavs9512/qk-server/config" | ||
"github.com/Firdavs9512/qk-server/core" | ||
) | ||
|
||
func TestConfigFileDirectory(t *testing.T) { | ||
// Create directory | ||
core.CreateDirectory(config.App.UploadUrl) | ||
|
||
// Check if directory exists | ||
if _, err := os.Stat(config.App.UploadUrl); os.IsNotExist(err) { | ||
t.Errorf("Directory was not created") | ||
} | ||
|
||
// Remove directory | ||
os.Remove(config.App.UploadUrl) | ||
} | ||
|
||
func TestCreateDirectory(t *testing.T) { | ||
// Create directory | ||
core.CreateDirectory("ExampleDirectory") | ||
|
||
// Check if directory exists | ||
if _, err := os.Stat("ExampleDirectory"); os.IsNotExist(err) { | ||
t.Errorf("Directory was not created") | ||
} | ||
|
||
// Remove directory | ||
os.Remove("ExampleDirectory") | ||
} |
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,22 @@ | ||
package database_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/Firdavs9512/qk-server/config" | ||
) | ||
|
||
func TestFilesModel(t *testing.T) { | ||
config.Database.Init() | ||
|
||
// Files model exists | ||
if !config.Database.DB.Migrator().HasTable("files") { | ||
t.Errorf("Table files does not exist") | ||
} | ||
|
||
// Delete database file if it exists | ||
if config.Database.GetConnection() == "sqlite" { | ||
os.Remove(config.Database.GetHost()) | ||
} | ||
} |
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,23 @@ | ||
package database_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/Firdavs9512/qk-server/config" | ||
) | ||
|
||
func TestDatabaseInit(t *testing.T) { | ||
// Test your database connection here | ||
config.Database.Init() | ||
|
||
// Test if the database is connected | ||
if config.Database.DB == nil { | ||
t.Errorf("Database is not connected") | ||
} | ||
|
||
// Delete database file if it exists | ||
if config.Database.GetConnection() == "sqlite" { | ||
os.Remove(config.Database.GetHost()) | ||
} | ||
} |