
This commit adds a complete Go implementation of the Todo application. The application uses Gin framework for the web server, GORM for database access, and SQLite for storage. Key features: - Todo CRUD operations with the same API endpoints - Health check endpoint - Database migrations - Tests for models, services, and API handlers - Documentation for the API - Configurable settings
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTodoTableName(t *testing.T) {
|
|
todo := Todo{}
|
|
if todo.TableName() != "todos" {
|
|
t.Errorf("Expected table name to be 'todos', got '%s'", todo.TableName())
|
|
}
|
|
}
|
|
|
|
func TestTodoFields(t *testing.T) {
|
|
// Create a todo
|
|
now := time.Now()
|
|
todo := Todo{
|
|
ID: 1,
|
|
Title: "Test Todo",
|
|
Description: "Test Description",
|
|
Completed: false,
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
}
|
|
|
|
// Check field values
|
|
if todo.ID != 1 {
|
|
t.Errorf("Expected ID to be 1, got %d", todo.ID)
|
|
}
|
|
|
|
if todo.Title != "Test Todo" {
|
|
t.Errorf("Expected Title to be 'Test Todo', got '%s'", todo.Title)
|
|
}
|
|
|
|
if todo.Description != "Test Description" {
|
|
t.Errorf("Expected Description to be 'Test Description', got '%s'", todo.Description)
|
|
}
|
|
|
|
if todo.Completed != false {
|
|
t.Errorf("Expected Completed to be false, got %t", todo.Completed)
|
|
}
|
|
|
|
if !todo.CreatedAt.Equal(now) {
|
|
t.Errorf("Expected CreatedAt to be %v, got %v", now, todo.CreatedAt)
|
|
}
|
|
|
|
if !todo.UpdatedAt.Equal(now) {
|
|
t.Errorf("Expected UpdatedAt to be %v, got %v", now, todo.UpdatedAt)
|
|
}
|
|
} |