Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
test: fix golden file for TDD
Browse files Browse the repository at this point in the history
  • Loading branch information
ginokent committed Nov 10, 2023
1 parent 98f8180 commit 8de0c64
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
19 changes: 19 additions & 0 deletions internal/arcgen/lang/go/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package arcgengo

import (
"context"
"io"
"os"
"testing"

"github.com/kunitsucom/util.go/testing/assert"
"github.com/kunitsucom/util.go/testing/require"

"github.com/kunitsucom/arcgen/internal/config"
Expand All @@ -28,6 +31,22 @@ func TestGenerate(t *testing.T) {

fileSuffix = ".source"
require.NoError(t, Generate(ctx, config.Source()))

{
expectedFile, err := os.Open("tests/common.golden")
require.NoError(t, err)
expectedBytes, err := io.ReadAll(expectedFile)
require.NoError(t, err)
expected := string(expectedBytes)

actualFile, err := os.Open("tests/common.dbtest.gen.source")
require.NoError(t, err)
actualBytes, err := io.ReadAll(actualFile)
require.NoError(t, err)
actual := string(actualBytes)

assert.Equal(t, expected, actual)
}
})

t.Run("failure,no.errsource", func(t *testing.T) {
Expand Down
24 changes: 24 additions & 0 deletions internal/arcgen/lang/go/tests/common.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ func (s *User) GetColumnName_Email() string {
func (s *User) GetColumnName_Age() string {
return "Age"
}

func (s *Users) GetTableName() string {
return "`Users`"
}

func (s *Users) GetColumnNames() []string {
return []string{"Id", "Name", "Email", "Age"}
}

func (s *Users) GetColumnName_Id() string {
return "Id"
}

func (s *Users) GetColumnName_Name() string {
return "Name"
}

func (s *Users) GetColumnName_Email() string {
return "Email"
}

func (s *Users) GetColumnName_Age() string {
return "Age"
}
5 changes: 3 additions & 2 deletions internal/arcgen/lang/go/tests/common.source
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type (
Ignore string `dbtest:"-"`
}

// dbtest: table: `SliceUsers`
SliceUser []*User
// Users is a slice of User.
//
Users []*User

// dbtest: table: `InvalidUsers`
InvalidUser struct {
Expand Down

0 comments on commit 8de0c64

Please sign in to comment.