testing-patterns-go
Installation
SKILL.md
Testing Couchbase Go Applications
Unit Testing
Define an interface for your collection operations and mock it with testify/mock.
import (
"testing"
"github.com/couchbase/gocb/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type CollectionOps interface {
Get(id string, opts *gocb.GetOptions) (*gocb.GetResult, error)
Upsert(id string, val interface{}, opts *gocb.UpsertOptions) (*gocb.MutationResult, error)
}