Skip to content

tdakkota/vksdkutil

Repository files navigation

VK SDK Utilities

CI Documentation codecov license

Some useful things for vksdk

Features

Middleware example

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

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

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)
	}
}