Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/test and deployment #10

Merged
merged 4 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Testing

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22

- name: Install Dependencies
run: go mod download

- name: Run Tests
run: go test -v ./test/...
8 changes: 8 additions & 0 deletions config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func (d *DatabaseType) Set(db *DatabaseType) {
Database = *db
}

func (d *DatabaseType) GetConnection() string {
return d.connection
}

func (d *DatabaseType) GetHost() string {
return d.host
}

func (d *DatabaseType) Init() {
var err error
d.DB, err = gorm.Open(sqlite.Open(d.host), &gorm.Config{})
Expand Down
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())
}
}
Loading