Initial commit

This commit is contained in:
2025-03-20 22:23:25 -03:00
parent d4a696a5fb
commit bc675abb58
8 changed files with 241 additions and 0 deletions

47
tests/api_test.go Normal file
View File

@@ -0,0 +1,47 @@
package tests
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"Tasker_API/internal/routes"
"github.com/gin-gonic/gin"
)
func TestPing(t *testing.T) {
// Set Gin into test mode
gin.SetMode(gin.TestMode)
// Initialize router with routes
router := gin.Default()
routes.InitializeRoutes(router)
// Create a test HTTP request for the /ping endpoint
req, err := http.NewRequest("GET", "/ping", nil)
if err != nil {
t.Fatalf("Failed to create request: %v", err)
}
// Use httptest to record the response
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
// Check for 200 OK status
if w.Code != http.StatusOK {
t.Fatalf("Expected status code 200, got %d", w.Code)
}
// Parse the JSON response body
var response map[string]string
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
t.Fatalf("Failed to parse JSON response: %v", err)
}
// Check for the expected message
if msg, exists := response["message"]; !exists || msg != "pong" {
t.Errorf("Expected message 'pong', got '%v'", response["message"])
}
}