Skip to content

Commit

Permalink
[new] Write database and core file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Firdavs9512 committed Mar 23, 2024
1 parent 5ee3914 commit eef13d1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/core/fileDirectory_test.go
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")
}
22 changes: 22 additions & 0 deletions test/database/FilesModel_test.go
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())
}
}
23 changes: 23 additions & 0 deletions test/database/init_test.go
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())
}
}

0 comments on commit eef13d1

Please sign in to comment.