exceltesting

package module
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

README

go-exceltesting

GoDev test

GoでExcelを使ったテーブルドリブンテストを行うためのヘルパーライブラリです。

ローカル環境でデータベースを含めた単体テストをするために、機能で必要な事前データをデータベースに投入する必要があります。 また正しくデータが更新されたことを検証するために、機能で更新した結果と想定している結果を比較する必要があります。

go-exceltesting ではこうしたデータベースへの事前データの投入や、実際の更新結果と期待結果の比較をより効率的に行うためのAPIを提供します。 視認性に優れることから事前データや期待するデータはExcelを使います。

現在は PostgreSQL のみサポートしています。

使い方

インストール

go get github.com/future-architect/go-exceltesting@latest

CLI インターフェース

テストに用いるExcelテンプレートの生成や、比較などをCLIコマンド経由で生成、確認できます。

Install
go install github.com/future-architect/go-exceltesting/cmd/exceltesting@latest
Setup

This cli tool needs to connect database. Accept connection url by -c option or environment variables.

# Mac/Linux
export EXCELTESTING_CONNECTION=postgres://username:password@localhost:5432/postgres?sslmode=disable

# Windows
set EXCELTESTING_CONNECTION=postgres://username:password@localhost:5432/postgres?sslmode=disable
Example

Generate excel template file.

$ exceltesting dump out.xlsx

Compare Database and excel file.

$ exceltesting compare testdata/compare.xlsx

Load test data.

$ exceltesting load testdata/load.xlsx

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadRaw added in v0.3.0

func LoadRaw(tx *sql.Tx, r LoadRawRequest) error

LoadRaw はGoの値からデータベースにデータを投入します。コミットは行いません。

func New

func New(db *sql.DB) *exceltesing

New はExcelからテストデータを投入できる構造体のファクトリ関数です

Types

type CompareRequest

type CompareRequest struct {
	// ロード対象Excelパス
	TargetBookPath string
	// ロード対象シートプレフィックス
	SheetPrefix string
	// 無視シート
	IgnoreSheet []string
	// 無視するカラム名
	IgnoreColumns []string
	// EnableDumpCSV はExcelファイルをCSVファイルとしてDumpします
	EnableDumpCSV bool
}

CompareRequest はExcelとデータベースの値を比較するための設定です。

type DumpRequest

type DumpRequest struct {
	// dump対象Excelパス
	TargetBookPaths []string
}

DumpRequest はExcelをCSVにDumpするための設定です。

type LoadRawRequest added in v0.3.0

type LoadRawRequest struct {
	TableName string
	Columns   []string
	Values    [][]string
}

LoadRawRequest はGoの値から直接データベースにデータを投入するための設定です。

type LoadRequest

type LoadRequest struct {
	// ロード対象Excelパス
	TargetBookPath string
	// ロード対象シートプレフィックス
	SheetPrefix string
	// 無視シート
	IgnoreSheet []string
	// EnableAutoCompleteNotNullColumn はExcel上でカラムの指定がない場合にデフォルト値で補完します
	// カラムにNOT NULL制約がある場合のみ補完します
	EnableAutoCompleteNotNullColumn bool
	// EnableDumpCSV はExcelファイルをCSVファイルとしてDumpします
	EnableDumpCSV bool
}

LoadRequest はExcelからデータを投入するための設定です。

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL