https://github.com/tdakkota/vksdkutil
Some useful things for vksdk
https://github.com/tdakkota/vksdkutil
logging metrics middleware testing testutil vksdk
Last synced: 11 months ago
JSON representation
Some useful things for vksdk
- Host: GitHub
- URL: https://github.com/tdakkota/vksdkutil
- Owner: tdakkota
- License: mit
- Created: 2020-05-25T15:10:40.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-19T04:57:27.000Z (about 3 years ago)
- Last Synced: 2024-10-18T21:17:03.383Z (over 1 year ago)
- Topics: logging, metrics, middleware, testing, testutil, vksdk
- Language: Go
- Homepage:
- Size: 180 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VK SDK Utilities
[](https://github.com/tdakkota/vksdkutil/actions)
[](https://pkg.go.dev/github.com/tdakkota/vksdkutil?tab=subdirectories)
[](https://codecov.io/gh/tdakkota/vksdkutil)
[](https://github.com/tdakkota/vksdkutil/blob/master/LICENSE)
Some useful things for [vksdk](https://github.com/SevereCloud/vksdk)
## Features
- Handler middlewares
- [Logging](https://github.com/tdakkota/vksdkutil/tree/master/middleware/log)
- [Retrying](https://github.com/tdakkota/vksdkutil/blob/master/middleware/README.md)
- [Caching](https://github.com/tdakkota/vksdkutil/blob/master/middleware/cache/README.md)
- `testutil` package for `api.VK` mocking
## Middleware example
```go
package main
import (
"github.com/SevereCloud/vksdk/v2/api"
sdkutil "github.com/tdakkota/vksdkutil/v3"
"github.com/tdakkota/vksdkutil/v3/middleware/zapvk"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
vk := sdkutil.BuildSDK("token").WithMiddleware(
zapvk.Log(zap.L(), zapcore.DebugLevel, true),
).Complete()
// ...
}
```
## Testing example
You have a file
```go
package mypackage
import (
"github.com/SevereCloud/vksdk/api"
)
func MarkAsRead(sdk *api.VK, peerID int) (int, error) {
builder := params.NewMessagesMarkAsReadBuilder()
builder.PeerID(peerID)
return sdk.MessagesMarkAsRead(builder.Params)
}
```
So, with `testutil` you can test it
```go
package mypackage
import (
"testing"
"github.com/tdakkota/vksdkutil/testutil"
)
func TestMarkAsRead(t *testing.T) {
sdk, expect := testutil.CreateSDK(t)
peerID, count := 10, 2
expect.ExpectCall("messages.markAsRead").WithParams(api.Params{
"peer_id": peerID,
}).ReturnsJSON(count)
read, err := MarkAsRead(sdk, peerID)
if err != nil {
t.Fatal(err)
}
if count != read {
t.Errorf("expected %d, got %d", count, read)
}
}
```