All Projects → gusaul → Go Dynamock

gusaul / Go Dynamock

Licence: mit
Amazon Dynamo DB Mock Driver for Golang to Test Database Interactions

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Dynamock

Dynomite
⚡🦀 🧨 make your rust types fit DynamoDB and visa versa
Stars: ✭ 144 (+102.82%)
Mutual labels:  nosql, dynamodb
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (-63.38%)
Mutual labels:  mock, tdd
dynamodb-onetable
DynamoDB access and management for one table designs with NodeJS
Stars: ✭ 508 (+615.49%)
Mutual labels:  nosql, dynamodb
Pester
Pester is the ubiquitous test and mock framework for PowerShell.
Stars: ✭ 2,620 (+3590.14%)
Mutual labels:  mock, tdd
Mockk
mocking library for Kotlin
Stars: ✭ 4,214 (+5835.21%)
Mutual labels:  mock, tdd
Mockito Scala
Mockito for Scala language
Stars: ✭ 231 (+225.35%)
Mutual labels:  mock, tdd
jest-dynalite
Jest preset to run Dynalite (DynamoDB local) per test runner
Stars: ✭ 125 (+76.06%)
Mutual labels:  mock, dynamodb
dynobase
Dynobase - Professional GUI Client for DynamoDB (releases / issues / roadmap repository) https://dynobase.dev
Stars: ✭ 66 (-7.04%)
Mutual labels:  nosql, dynamodb
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (+428.17%)
Mutual labels:  mock, tdd
Go Sqlmock
Sql mock driver for golang to test database interactions
Stars: ✭ 4,003 (+5538.03%)
Mutual labels:  mock, tdd
Python Mocket
a socket mock framework - for all kinds of socket animals, web-clients included
Stars: ✭ 209 (+194.37%)
Mutual labels:  mock, tdd
Webmockr
R library for stubbing and setting expectations on HTTP requests
Stars: ✭ 37 (-47.89%)
Mutual labels:  mock, tdd
Gunit
GUnit - Google.Test/Google.Mock/Cucumber on steroids
Stars: ✭ 156 (+119.72%)
Mutual labels:  mock, tdd
Dynein
DynamoDB CLI written in Rust.
Stars: ✭ 126 (+77.46%)
Mutual labels:  nosql, dynamodb
Httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module
Stars: ✭ 1,930 (+2618.31%)
Mutual labels:  mock, tdd
List Of Testing Tools And Frameworks For .net
✅ List of Automated Testing (TDD/BDD/ATDD/SBE) Tools and Frameworks for .NET
Stars: ✭ 303 (+326.76%)
Mutual labels:  mock, tdd
Dynamodb Toolbox
A simple set of tools for working with Amazon DynamoDB and the DocumentClient
Stars: ✭ 752 (+959.15%)
Mutual labels:  nosql, dynamodb
Moka
A Go mocking framework.
Stars: ✭ 53 (-25.35%)
Mutual labels:  mock, tdd
Jsonschema Key Compression
Compress json-data based on its json-schema while still having valid json
Stars: ✭ 59 (-16.9%)
Mutual labels:  nosql
Vue Admin Beautiful
🚀🚀🚀vue3 admin,vue3.0 admin,vue后台管理,vue-admin,vue3.0-admin,admin,vue-admin,vue-element-admin,ant-design,vue-admin-beautiful-pro,vab admin pro,vab admin plus主线版本基于element-plus、element-ui、ant-design-vue三者并行开发维护,同时支持电脑,手机,平板,切换分支查看不同的vue版本,element-plus版本已发布(vue3,vue3.0,vue,vue3.x,vue.js)
Stars: ✭ 10,968 (+15347.89%)
Mutual labels:  mock

GoDoc Go Report Card Build Status

go-dynamock

Amazon Dynamo DB Mock Driver for Golang to Test Database Interactions

Install

go get github.com/gusaul/go-dynamock

Examples Usage

Visit godoc for general examples and public api reference.

DynamoDB configuration

First of all, change the dynamodb configuration to use the dynamodb interface. see code below:

package main

import (
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/dynamodb"
    "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
)

type MyDynamo struct {
    Db dynamodbiface.DynamoDBAPI
}

var Dyna *MyDynamo

func ConfigureDynamoDB() {
	Dyna = new(MyDynamo)
	awsSession, _ := session.NewSession(&aws.Config{Region: aws.String("ap-southeast-2")})
	svc := dynamodb.New(awsSession)
	Dyna.Db = dynamodbiface.DynamoDBAPI(svc)
}

the purpose of code above is to make your dynamoDB object can be mocked by dynamock through the dynamodbiface.

Something you may wanna test

package main

import (
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/dynamodb"
)

func GetName(id string) (*string, error) {
	parameter := &dynamodb.GetItemInput{
		Key: map[string]*dynamodb.AttributeValue{
			"id": {
				N: aws.String(id),
			},
		},
		TableName: aws.String("employee"),
	}

	response, err := Dyna.Db.GetItem(parameter)
	if err != nil {
		return nil, err
	}

	name := response.Item["name"].S
	return name, nil
}

Test with DynaMock

package examples

import (
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/dynamodb"
	dynamock "github.com/gusaul/go-dynamock"
)

var mock *dynamock.DynaMock

func init() {
	Dyna = new(MyDynamo)
	Dyna.Db, mock = dynamock.New()
}

func TestGetName(t *testing.T) {
	expectKey := map[string]*dynamodb.AttributeValue{
		"id": {
			N: aws.String("1"),
		},
	}

	expectedResult := aws.String("jaka")
	result := dynamodb.GetItemOutput{
		Item: map[string]*dynamodb.AttributeValue{
			"name": {
				S: expectedResult,
			},
		},
	}

	//lets start dynamock in action
	mock.ExpectGetItem().ToTable("employee").WithKeys(expectKey).WillReturns(result)

	actualResult, _ := GetName("1")
	if actualResult != expectedResult {
		t.Errorf("Test Fail")
	}
}

if you just wanna expect the table

mock.ExpectGetItem().ToTable("employee").WillReturns(result)

or maybe you didn't care with any arguments, you just need to determine the result

mock.ExpectGetItem().WillReturns(result)

and you can do multiple expectations at once, then the expectation will be executed sequentially.

mock.ExpectGetItem().WillReturns(resultOne)
mock.ExpectUpdateItem().WillReturns(resultTwo)
mock.ExpectGetItem().WillReturns(resultThree)

/* Result
the first call of GetItem will return resultOne
the second call of GetItem will return resultThree
and the only call of UpdateItem will return resultTwo */

Currently Supported Functions

CreateTable(*dynamodb.CreateTableInput) (*dynamodb.CreateTableOutput, error)
DescribeTable(*dynamodb.DescribeTableInput) (*dynamodb.DescribeTableOutput, error)
GetItem(*dynamodb.GetItemInput) (*dynamodb.GetItemOutput, error)
GetItemWithContext(aws.Context, *dynamodb.GetItemInput, ...request.Option) (*dynamodb.GetItemOutput, error)
PutItem(*dynamodb.PutItemInput) (*dynamodb.PutItemOutput, error)
PutItemWithContext(aws.Context, *dynamodb.PutItemInput, ...request.Option) (*dynamodb.PutItemOutput, error)
UpdateItem(*dynamodb.UpdateItemInput) (*dynamodb.UpdateItemOutput, error)
UpdateItemWithContext(aws.Context, *dynamodb.UpdateItemInput, ...request.Option) (*dynamodb.UpdateItemOutput, error)
DeleteItem(*dynamodb.DeleteItemInput) (*dynamodb.DeleteItemOutput, error)
DeleteItemWithContext(aws.Context, *dynamodb.DeleteItemInput, ...request.Option) (*dynamodb.DeleteItemOutput, error)
BatchGetItem(*dynamodb.BatchGetItemInput) (*dynamodb.BatchGetItemOutput, error)
BatchGetItemWithContext(aws.Context, *dynamodb.BatchGetItemInput, ...request.Option) (*dynamodb.BatchGetItemOutput, error)
BatchWriteItem(*dynamodb.BatchWriteItemInput) (*dynamodb.BatchWriteItemOutput, error)
BatchWriteItemWithContext(aws.Context, *dynamodb.BatchWriteItemInput, ...request.Option) (*dynamodb.BatchWriteItemOutput, error)
WaitUntilTableExists(*dynamodb.DescribeTableInput) error
Scan(input *dynamodb.ScanInput) (*dynamodb.ScanOutput, error)
ScanPages(input *ScanInput, fn func(*ScanOutput, bool) bool) error
ScanPagesWithContext(ctx aws.Context, input *ScanInput, fn func(*ScanOutput, bool) bool, opts ...request.Option) error
ScanWithContext(aws.Context, *dynamodb.ScanInput, ...request.Option) (*dynamodb.ScanOutput, error)
Query(input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error)
QueryWithContext(aws.Context, *dynamodb.QueryInput, request.Option) (*dynamodb.QueryOutput, error)
QueryPages(*dynamodb.QueryInput, func(*dynamodb.QueryOutput, bool) bool) error
QueryPagesWithContext(aws.Context, *dynamodb.QueryInput, func(*dynamodb.QueryOutput, bool) bool, ...request.Option) error

Contributions

Feel free to open a pull request. Note, if you wish to contribute an extension to public (exported methods or types) - please open an issue before, to discuss whether these changes can be accepted. All backward incompatible changes are and will be treated cautiously

License

The MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].