Skip to content

itbasis/go-test-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test utils

GitHub go.mod Go version godoc reference blue GitHub Release Go Report Card

Install module

go get -u github.com/itbasis/go-test-utils/v4

File utils

  • files/files.go - Reads the contents of a file and checks that there was no error while reading.

Real file system:

package demo_test

import (
	"os"

	"github.com/itbasis/go-test-utils/v4/files"
	"github.com/onsi/ginkgo/v2"
)

var _ = ginkgo.Describe("Real OS", func(){
	content := files.ReadFile(os.ReadFile, "example.txt")
})

Embedded File System:

package demo_test

import (
	"embed"

	"github.com/itbasis/go-test-utils/v4/files"
	"github.com/onsi/ginkgo/v2"
)

//go:embed example.txt
var testData embed.FS

var _ = ginkgo.Describe("Embedded FS", func(){
	content := files.ReadFile(testData.ReadFile, "example.txt")
})

Database utils

Ginkgo utils

package demo_test

import (
	"testing"

	"github.com/itbasis/go-test-utils/v4/ginkgo"
)

func TestSuite(t *testing.T) {
	ginkgo.InitGinkgoSuite(t, "Sample Suite")
}

Custom slog options

package demo_test

import (
	"log/slog"
	"testing"

	"github.com/itbasis/go-test-utils/v4/ginkgo"
)

func TestDemoSuite(t *testing.T) {
	ginkgo.InitGinkgoSuiteWithSlogOptions(t, "Sample Suite", &slog.HandlerOptions{
		Level: slog.LevelDebug,
		AddSource: false,
	})
}