Skip to content

Commit

Permalink
Update URL prefix in ShortenURLHandler and improve .env file loading …
Browse files Browse the repository at this point in the history
…in Redis setup; add tests for Redis client setup
  • Loading branch information
SartajBhuvaji committed Nov 23, 2024
1 parent 6abae4a commit a90acf7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/shorten.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ShortenURLHandler(w http.ResponseWriter, r *http.Request, redisClient *data
log.Println("Counter: ", counter)

enc := EncodeURL(counter)
shortURL := "something/" + enc
shortURL := "www.goURLShortner/" + enc

// Update the counter counter++
redisClient.SetCounter("counter", counter+1)
Expand Down
3 changes: 0 additions & 3 deletions tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func TestShortenURLHandler(t *testing.T) {
// create a response recorder
rec := httptest.NewRecorder()

// call the handler
// create a redis client (assuming you have a function to do this)

redisClient, err := utils.SetupRedis()
if err != nil {
t.Fatalf("could not set up Redis: %v", err)
Expand Down
15 changes: 15 additions & 0 deletions tests/df_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tests

import (
"testing"

"github.com/SartajBhuvaji/utils"
)

func TestSetupRedis(t *testing.T) {
redisClient, err := utils.SetupRedis()
if err != nil {
t.Fatalf("Failed to get Reddis Client %v", err)
}
defer redisClient.Close()
}
2 changes: 1 addition & 1 deletion utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ReverseString(s string) string {
}

func SetupRedis() (*database.RedisClient, error) {
err := godotenv.Load("../.env")
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file: %v", err)
}
Expand Down

0 comments on commit a90acf7

Please sign in to comment.