-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 [Bug]: cache middleware: runtime error: index out of range [0] with…
… length 0 (#3075) Resolves #3072 Signed-off-by: brunodmartins <[email protected]>
- Loading branch information
1 parent
2788a53
commit 25c9fa2
Showing
5 changed files
with
190 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cache | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/gofiber/utils/v2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_manager_get(t *testing.T) { | ||
t.Parallel() | ||
cacheManager := newManager(nil) | ||
t.Run("Item not found in cache", func(t *testing.T) { | ||
t.Parallel() | ||
assert.Nil(t, cacheManager.get(utils.UUID())) | ||
}) | ||
t.Run("Item found in cache", func(t *testing.T) { | ||
t.Parallel() | ||
id := utils.UUID() | ||
cacheItem := cacheManager.acquire() | ||
cacheItem.body = []byte("test-body") | ||
cacheManager.set(id, cacheItem, 10*time.Second) | ||
assert.NotNil(t, cacheManager.get(id)) | ||
}) | ||
} |