/hseq

Generate hash + sequence for tests

Primary LanguageGoMIT LicenseMIT

hseq

Build Status GitHub license Go Report Card

Simply generating sequence values for tests

Why created

In tests, it is very helpful to have unique sequence values for a name, especially when it interact with RDBMS primary key or unique constraints. This library makes it easier to set up unique sequence values in Go tests.

Installation

go get -u github.com/achiku/hseq

How to use

package main

import (
	"log"

	"github.com/achiku/hseq"
)

type st struct {
	ID           int64
	UniqueNumber int
	UniqueName   string
}

func main() {
	st1 := st{
		ID:           hseq.Get("st.id").Int64(),
		UniqueNumber: hseq.Get("st.unique_number").Int(),
		UniqueName:   hseq.Get("st.unique_name").String(),
	}
	st2 := st{
		ID:           hseq.Get("st.id").Int64(),
		UniqueNumber: hseq.Get("st.unique_number").Int(),
		UniqueName:   hseq.Get("st.unique_name").String(),
	}
	log.Printf("%+v", st1)
	log.Printf("%+v", st2)
}