LoginSignup
0
0

ent で 簡易的なテストを書く

Posted at

ent とは

Facebook社(Meta)提供のGolangのORM。公式サイト: ent

テストを書いてみる

使うもの

テストする関数とテーブル定義

後で書く

テストコード

import (
	"context"
	"testing"

	"<project>/ent/enttest"
	_ "github.com/mattn/go-sqlite3"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestCreateTeam(t *testing.T) {

  ctx := context.Background()
  client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&_fk=1")
  defer client.Close()
  err := client.Schema.Create(ctx)
  require.NoError(t, err)

  team := &setting.Team{
    Id:    1,
    Name: "エンジニアチーム",
  }

  _, err = client.Team.Create().
    SetName(team.Name).
    Save(ctx)
  require.NoError(t, err)
  
  team, err := CreateTeam(1)
  require.NoError(t, err)

  assert.NotNil(t, team)
  assert.Equal(t, "エンジニアチーム", team.Name)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0