logic_test.go 637 B

12345678910111213141516171819202122232425262728293031
  1. // FILEPATH: /root/CareyWang/MyUrls/logic_test.go
  2. package main
  3. import (
  4. "context"
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestLongToShortAndShortToLong(t *testing.T) {
  10. ctx := context.Background()
  11. initRedisClient(mockRedisOptions)
  12. shortKey := "testKey"
  13. longURL := "https://example.com"
  14. err := LongToShort(ctx, &LongToShortOptions{
  15. ShortKey: shortKey,
  16. URL: longURL,
  17. expiration: 60 * time.Second,
  18. })
  19. assert.NoError(t, err)
  20. // delete test data from redis
  21. defer GetRedisClient().Del(ctx, shortKey)
  22. resultLongURL := ShortToLong(ctx, shortKey)
  23. assert.Equal(t, longURL, resultLongURL)
  24. }