From 007db84bee936f87d54dcc3e2f4608748e203330 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 5 Jun 2024 21:56:15 +0200 Subject: [PATCH 1/5] feat: Add rate limiting middleware to backend API, limiting 5 requests per second --- occupi-backend/cmd/occupi-backend/main.go | 15 +++++++++++++++ occupi-backend/go.mod | 2 ++ occupi-backend/go.sum | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/occupi-backend/cmd/occupi-backend/main.go b/occupi-backend/cmd/occupi-backend/main.go index 708a6cf9..6c1a3601 100644 --- a/occupi-backend/cmd/occupi-backend/main.go +++ b/occupi-backend/cmd/occupi-backend/main.go @@ -7,6 +7,9 @@ import ( "github.com/gin-gonic/gin" "github.com/joho/godotenv" "github.com/sirupsen/logrus" + "github.com/ulule/limiter/v3" + mgin "github.com/ulule/limiter/v3/drivers/middleware/gin" + "github.com/ulule/limiter/v3/drivers/store/memory" "github.com/COS301-SE-2024/occupi/occupi-backend/configs" "github.com/COS301-SE-2024/occupi/occupi-backend/pkg/database" @@ -39,6 +42,18 @@ func main() { logrus.Fatal("Failed to set trusted proxies: ", err) } + // Define a rate limit: 5 requests per second + rate, _ := limiter.NewRateFromFormatted("5-S") + + store := memory.NewStore() + instance := limiter.New(store, rate) + + // Create the rate limiting middleware + middleware := mgin.NewMiddleware(instance) + + // Apply the middleware to the router + ginRouter.Use(middleware) + // Register routes router.OccupiRouter(ginRouter, db) diff --git a/occupi-backend/go.mod b/occupi-backend/go.mod index 9434acc9..94416e11 100644 --- a/occupi-backend/go.mod +++ b/occupi-backend/go.mod @@ -47,11 +47,13 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/montanaflynn/stats v0.7.1 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect + github.com/ulule/limiter/v3 v3.11.2 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect diff --git a/occupi-backend/go.sum b/occupi-backend/go.sum index 3dbdeb35..ad657591 100644 --- a/occupi-backend/go.sum +++ b/occupi-backend/go.sum @@ -84,6 +84,8 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8 github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= @@ -108,6 +110,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ulule/limiter/v3 v3.11.2 h1:P4yOrxoEMJbOTfRJR2OzjL90oflzYPPmWg+dvwN2tHA= +github.com/ulule/limiter/v3 v3.11.2/go.mod h1:QG5GnFOCV+k7lrL5Y8kgEeeflPH3+Cviqlqa8SVSQxI= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= From 0c5dc37cd5ca18767f5de67b130b1a51979333ed Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 5 Jun 2024 22:03:17 +0200 Subject: [PATCH 2/5] chore: Add rate limiting middleware to backend API, limiting 5 requests per second --- occupi-backend/tests/handlers_test.go | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/occupi-backend/tests/handlers_test.go b/occupi-backend/tests/handlers_test.go index 89b723f5..7c864331 100644 --- a/occupi-backend/tests/handlers_test.go +++ b/occupi-backend/tests/handlers_test.go @@ -4,7 +4,11 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "sync" "testing" + "time" + + "github.com/stretchr/testify/assert" "github.com/gin-gonic/gin" // "github.com/joho/godotenv" @@ -175,6 +179,43 @@ func TestPingRoute(t *testing.T) { } } +func TestRateLimit(t *testing.T) { + router := setupRouter() + server := httptest.NewServer(router) + defer server.Close() + + var wg sync.WaitGroup + numRequests := 10 + responseCodes := make([]int, numRequests) + + for i := 0; i < numRequests; i++ { + wg.Add(1) + go func(index int) { + defer wg.Done() + resp, err := http.Get(server.URL + "/ping") + if err != nil { + t.Errorf("Request %d failed: %v", index, err) + return + } + defer resp.Body.Close() + responseCodes[index] = resp.StatusCode + }(i) + time.Sleep(100 * time.Millisecond) // Slight delay to spread out the requests + } + + wg.Wait() + + rateLimitedCount := 0 + for _, code := range responseCodes { + if code == http.StatusTooManyRequests { + rateLimitedCount++ + } + } + + assert.Greater(t, rateLimitedCount, 0, "There should be some requests that are rate limited") + assert.LessOrEqual(t, rateLimitedCount, numRequests-5, "There should be at least 5 requests that are not rate limited") +} + /* func TestGetResource(t *testing.T) { // Load environment variables from .env file From 46f8e0bb216d2df8da9e9e944933f6931870726d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Jun 2024 10:31:17 +0200 Subject: [PATCH 3/5] chore: Update test command to include verbose output and introduced working test for rate limiter --- .github/workflows/lint-test-build-golang.yml | 2 +- occupi-backend/cmd/occupi-backend/main.go | 17 ++-------- occupi-backend/occupi.bat | 4 +-- occupi-backend/occupi.sh | 4 +-- occupi-backend/pkg/middleware/middleware.go | 34 +++++++++++++++----- occupi-backend/tests/handlers_test.go | 14 +++++++- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/.github/workflows/lint-test-build-golang.yml b/.github/workflows/lint-test-build-golang.yml index c56faf9c..c77465fd 100644 --- a/.github/workflows/lint-test-build-golang.yml +++ b/.github/workflows/lint-test-build-golang.yml @@ -54,7 +54,7 @@ jobs: - name: Run tests run: | - go test ./tests/... -race -coverprofile=coverage.out -covermode=atomic + go test -v ./tests/... -race -coverprofile=coverage.out -covermode=atomic - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/occupi-backend/cmd/occupi-backend/main.go b/occupi-backend/cmd/occupi-backend/main.go index 6c1a3601..4c9d7292 100644 --- a/occupi-backend/cmd/occupi-backend/main.go +++ b/occupi-backend/cmd/occupi-backend/main.go @@ -7,12 +7,10 @@ import ( "github.com/gin-gonic/gin" "github.com/joho/godotenv" "github.com/sirupsen/logrus" - "github.com/ulule/limiter/v3" - mgin "github.com/ulule/limiter/v3/drivers/middleware/gin" - "github.com/ulule/limiter/v3/drivers/store/memory" "github.com/COS301-SE-2024/occupi/occupi-backend/configs" "github.com/COS301-SE-2024/occupi/occupi-backend/pkg/database" + "github.com/COS301-SE-2024/occupi/occupi-backend/pkg/middleware" "github.com/COS301-SE-2024/occupi/occupi-backend/pkg/router" "github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils" ) @@ -42,17 +40,8 @@ func main() { logrus.Fatal("Failed to set trusted proxies: ", err) } - // Define a rate limit: 5 requests per second - rate, _ := limiter.NewRateFromFormatted("5-S") - - store := memory.NewStore() - instance := limiter.New(store, rate) - - // Create the rate limiting middleware - middleware := mgin.NewMiddleware(instance) - - // Apply the middleware to the router - ginRouter.Use(middleware) + //adding rate limiting middleware + middleware.AttachRateLimitMiddleware(ginRouter) // Register routes router.OccupiRouter(ginRouter, db) diff --git a/occupi-backend/occupi.bat b/occupi-backend/occupi.bat index 9e9c1b34..6fe11498 100644 --- a/occupi-backend/occupi.bat +++ b/occupi-backend/occupi.bat @@ -20,10 +20,10 @@ if "%1 %2" == "run dev" ( docker-compose up exit /b 0 ) else if "%1" == "test" ( - go test ./tests/... + go test -v ./tests/... exit /b 0 ) else if "%1 %2" == "test codecov" ( - go test ./tests/... -race -coverprofile=coverage.out -covermode=atomic + go test -v ./tests/... -race -coverprofile=coverage.out -covermode=atomic exit /b 0 ) else if "%1" == "lint" ( golangci-lint run diff --git a/occupi-backend/occupi.sh b/occupi-backend/occupi.sh index f103618c..d9cba68e 100644 --- a/occupi-backend/occupi.sh +++ b/occupi-backend/occupi.sh @@ -29,9 +29,9 @@ elif [ "$1" = "docker" ] && [ "$2" = "build" ]; then elif [ "$1" = "docker" ] && [ "$2" = "up" ]; then docker-compose up elif [ "$1" = "test" ]; then - go test ./tests/... + go test -v ./tests/... elif [ "$1" = "test" ] && [ "$2" = "codecov" ]; then - go test ./tests/... -race -coverprofile=coverage.out -covermode=atomic + go test -v ./tests/... -race -coverprofile=coverage.out -covermode=atomic elif [ "$1" = "lint" ]; then golangci-lint run elif [ "$1" = "help" ] || [ -z "$1" ]; then diff --git a/occupi-backend/pkg/middleware/middleware.go b/occupi-backend/pkg/middleware/middleware.go index 1fdf1651..e4fc8f97 100644 --- a/occupi-backend/pkg/middleware/middleware.go +++ b/occupi-backend/pkg/middleware/middleware.go @@ -5,34 +5,52 @@ import ( "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" + "github.com/ulule/limiter/v3" + mgin "github.com/ulule/limiter/v3/drivers/middleware/gin" + "github.com/ulule/limiter/v3/drivers/store/memory" ) // ProtectedRoute is a middleware that checks if // the user has already been authenticated previously. -func ProtectedRoute(c *gin.Context) { - if sessions.Default(c).Get("profile") == nil { +func ProtectedRoute(ctx *gin.Context) { + if sessions.Default(ctx).Get("profile") == nil { // If the user is not authenticated, return a 401 Unauthorized response - c.JSON(http.StatusUnauthorized, gin.H{ + ctx.JSON(http.StatusUnauthorized, gin.H{ "status": http.StatusUnauthorized, "message": "Bad Request", "error": "User not authenticated", }) } else { - c.Next() + ctx.Next() } } // ProtectedRoute is a middleware that checks if // the user has not been authenticated previously. -func UnProtectedRoute(c *gin.Context) { - if sessions.Default(c).Get("profile") != nil { +func UnProtectedRoute(ctx *gin.Context) { + if sessions.Default(ctx).Get("profile") != nil { // If the user is authenticated, return a 401 Unauthorized response - c.JSON(http.StatusUnauthorized, gin.H{ + ctx.JSON(http.StatusUnauthorized, gin.H{ "status": http.StatusUnauthorized, "message": "Bad Request", "error": "User already authenticated", }) } else { - c.Next() + ctx.Next() } } + +// AttachRateLimitMiddleware attaches the rate limit middleware to the router. +func AttachRateLimitMiddleware(ginRouter *gin.Engine) { + // Define a rate limit: 5 requests per second + rate, _ := limiter.NewRateFromFormatted("5-S") + + store := memory.NewStore() + instance := limiter.New(store, rate) + + // Create the rate limiting middleware + middleware := mgin.NewMiddleware(instance) + + // Apply the middleware to the router + ginRouter.Use(middleware) +} diff --git a/occupi-backend/tests/handlers_test.go b/occupi-backend/tests/handlers_test.go index 7c864331..fd34ec97 100644 --- a/occupi-backend/tests/handlers_test.go +++ b/occupi-backend/tests/handlers_test.go @@ -11,6 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/gin-gonic/gin" + + "github.com/COS301-SE-2024/occupi/occupi-backend/pkg/middleware" // "github.com/joho/godotenv" // "github.com/stretchr/testify/assert" // "github.com/stretchr/testify/mock" @@ -180,7 +182,17 @@ func TestPingRoute(t *testing.T) { } func TestRateLimit(t *testing.T) { - router := setupRouter() + // Create a new Gin router + router := gin.Default() + + // attach rate limit middleware + middleware.AttachRateLimitMiddleware(router) + + // Register the route + router.GET("/ping", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "pong -> I am alive and kicking"}) + }) + server := httptest.NewServer(router) defer server.Close() From a4e689025aa5499f2d0c53734913dffbe697c561 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Jun 2024 11:00:41 +0200 Subject: [PATCH 4/5] fix and feat: added rate limiting for multiple ip's and fixed linting errors --- occupi-backend/cmd/occupi-backend/main.go | 2 +- occupi-backend/tests/handlers_test.go | 91 +++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/occupi-backend/cmd/occupi-backend/main.go b/occupi-backend/cmd/occupi-backend/main.go index 4c9d7292..3b4a854e 100644 --- a/occupi-backend/cmd/occupi-backend/main.go +++ b/occupi-backend/cmd/occupi-backend/main.go @@ -40,7 +40,7 @@ func main() { logrus.Fatal("Failed to set trusted proxies: ", err) } - //adding rate limiting middleware + // adding rate limiting middleware middleware.AttachRateLimitMiddleware(ginRouter) // Register routes diff --git a/occupi-backend/tests/handlers_test.go b/occupi-backend/tests/handlers_test.go index fd34ec97..b301cf54 100644 --- a/occupi-backend/tests/handlers_test.go +++ b/occupi-backend/tests/handlers_test.go @@ -228,6 +228,97 @@ func TestRateLimit(t *testing.T) { assert.LessOrEqual(t, rateLimitedCount, numRequests-5, "There should be at least 5 requests that are not rate limited") } +func TestRateLimitWithMultipleIPs(t *testing.T) { + // Create a new Gin router + router := gin.Default() + + // attach rate limit middleware + middleware.AttachRateLimitMiddleware(router) + + // Register the route + router.GET("/ping", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"message": "pong -> I am alive and kicking"}) + }) + + server := httptest.NewServer(router) + defer server.Close() + + var wg sync.WaitGroup + numRequests := 10 + ip1 := "192.168.1.1" + ip2 := "192.168.1.2" + responseCodesIP1 := make([]int, numRequests) + responseCodesIP2 := make([]int, numRequests-5) + + // Send requests from the first IP address + for i := 0; i < numRequests; i++ { + wg.Add(1) + go func(index int) { + defer wg.Done() + client := &http.Client{} + req, err := http.NewRequest("GET", server.URL+"/ping", nil) + if err != nil { + t.Errorf("Failed to create request: %v", err) + return + } + req.Header.Set("X-Forwarded-For", ip1) + resp, err := client.Do(req) + if err != nil { + t.Errorf("Request failed: %v", err) + return + } + defer resp.Body.Close() + responseCodesIP1[index] = resp.StatusCode + }(i) + time.Sleep(10 * time.Millisecond) // Slight delay to spread out the requests + } + + // Send requests from the second IP address + for i := 0; i < numRequests-5; i++ { + wg.Add(1) + go func(index int) { + defer wg.Done() + client := &http.Client{} + req, err := http.NewRequest("GET", server.URL+"/ping", nil) + if err != nil { + t.Errorf("Failed to create request: %v", err) + return + } + req.Header.Set("X-Forwarded-For", ip2) + resp, err := client.Do(req) + if err != nil { + t.Errorf("Request failed: %v", err) + return + } + defer resp.Body.Close() + responseCodesIP2[index] = resp.StatusCode + }(i) + time.Sleep(10 * time.Millisecond) // Slight delay to spread out the requests + } + + wg.Wait() + + rateLimitedCountIP1 := 0 + rateLimitedCountIP2 := 0 + for _, code := range responseCodesIP1 { + if code == http.StatusTooManyRequests { + rateLimitedCountIP1++ + } + } + for _, code := range responseCodesIP2 { + if code == http.StatusTooManyRequests { + rateLimitedCountIP2++ + } + } + + // Assertions for IP1 + assert.Greater(t, rateLimitedCountIP1, 0, "There should be some requests from IP1 that are rate limited") + assert.LessOrEqual(t, rateLimitedCountIP1, numRequests-5, "There should be at least 5 requests from IP1 that are not rate limited") + + // Assertions for IP2 + assert.Equal(t, rateLimitedCountIP2, 0, "There should be no requests from IP2 that are rate limited") +} + /* func TestGetResource(t *testing.T) { // Load environment variables from .env file From 78692b5b7a6342207058c8791b6681d796c2c328 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Jun 2024 11:36:47 +0200 Subject: [PATCH 5/5] fix: addressing codecov issues --- .github/workflows/lint-test-build-golang.yml | 2 +- occupi-backend/coverage.out | 47 ++++++++++++++++++++ occupi-backend/occupi.bat | 2 +- occupi-backend/occupi.sh | 2 +- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 occupi-backend/coverage.out diff --git a/.github/workflows/lint-test-build-golang.yml b/.github/workflows/lint-test-build-golang.yml index c77465fd..0c768a13 100644 --- a/.github/workflows/lint-test-build-golang.yml +++ b/.github/workflows/lint-test-build-golang.yml @@ -54,7 +54,7 @@ jobs: - name: Run tests run: | - go test -v ./tests/... -race -coverprofile=coverage.out -covermode=atomic + go test -v -coverpkg=github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/handlers ./tests/... -coverprofile=coverage.out - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/occupi-backend/coverage.out b/occupi-backend/coverage.out new file mode 100644 index 00000000..c42c0e72 --- /dev/null +++ b/occupi-backend/coverage.out @@ -0,0 +1,47 @@ +mode: set +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/OTP.go:9.36,12.16 3 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/OTP.go:12.16,14.3 1 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/OTP.go:15.2,16.21 2 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/response.go:16.9,22.2 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/response.go:30.9,37.2 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/response.go:46.9,56.2 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/response.go:59.34,69.2 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/response.go:79.9,90.2 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:22.20,27.16 3 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:27.16,29.3 1 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:33.2,42.35 3 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:46.42,50.16 4 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:50.16,52.3 1 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:53.2,55.17 3 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:59.34,62.16 3 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:62.16,64.3 1 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:65.2,66.19 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:70.44,73.16 3 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:73.16,75.3 1 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:77.2,79.19 2 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:83.94,89.31 4 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:89.31,91.25 2 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:91.25,93.62 2 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:93.62,97.5 3 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:102.2,104.20 2 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:108.41,111.2 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:114.39,118.2 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:121.45,130.23 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:130.23,132.3 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:134.2,134.44 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:134.44,136.3 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:138.2,138.44 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:138.44,140.3 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:142.2,142.34 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:142.34,144.3 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:146.2,146.40 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:146.40,148.3 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:150.2,150.13 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:154.35,158.2 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:161.52,167.16 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:167.16,169.3 1 0 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:170.2,170.18 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:174.80,178.16 2 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:178.16,180.3 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:181.2,181.19 1 1 +github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils/utils.go:184.20,187.2 0 0 diff --git a/occupi-backend/occupi.bat b/occupi-backend/occupi.bat index 6fe11498..f59efabe 100644 --- a/occupi-backend/occupi.bat +++ b/occupi-backend/occupi.bat @@ -23,7 +23,7 @@ if "%1 %2" == "run dev" ( go test -v ./tests/... exit /b 0 ) else if "%1 %2" == "test codecov" ( - go test -v ./tests/... -race -coverprofile=coverage.out -covermode=atomic + go test -v -coverpkg=github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/handlers ./tests/... -coverprofile=coverage.out exit /b 0 ) else if "%1" == "lint" ( golangci-lint run diff --git a/occupi-backend/occupi.sh b/occupi-backend/occupi.sh index d9cba68e..0c6f8f12 100644 --- a/occupi-backend/occupi.sh +++ b/occupi-backend/occupi.sh @@ -31,7 +31,7 @@ elif [ "$1" = "docker" ] && [ "$2" = "up" ]; then elif [ "$1" = "test" ]; then go test -v ./tests/... elif [ "$1" = "test" ] && [ "$2" = "codecov" ]; then - go test -v ./tests/... -race -coverprofile=coverage.out -covermode=atomic + go test -v -coverpkg=github.com/COS301-SE-2024/occupi/occupi-backend/pkg/utils,github.com/COS301-SE-2024/occupi/occupi-backend/pkg/handlers ./tests/... -coverprofile=coverage.out elif [ "$1" = "lint" ]; then golangci-lint run elif [ "$1" = "help" ] || [ -z "$1" ]; then