From 08bed4b4f7270b664851713f0cfac670ae4d54d0 Mon Sep 17 00:00:00 2001 From: Tatsuro Miyamoto <43370894+tamiyamoto@users.noreply.github.com> Date: Wed, 12 Oct 2022 16:50:23 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=BC=E3=83=86=E3=82=A3=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C=20(#46)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * パーティションテーブル対応 * テスト修正 * コメント追加 --- compare.xlsx | Bin 0 -> 8320 bytes exceltesting_test.go | 57 +++++++++++++++++++++++++++++----------- query.go | 2 +- testdata/schema/ddl.sql | 13 +++++++++ 4 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 compare.xlsx diff --git a/compare.xlsx b/compare.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..d1d8d18306a212b99f5baa2b38aa56a2b3643392 GIT binary patch literal 8320 zcmaKSbzIfU^Zr4)8>G8iy1P@lk&-%eOCup2N_UrZcc(N6(jC$%lKu{Iz258ne1H4L ziPxED-m^2i&&0w3*GN2gt;$6ZNGpY7KHMAwY1nV=IXRu}^!KuCdCV^~Zh>gh? zWYYHIwi|eL&X%m9(3tSbQ1A0AF0NCrU3xzDs}ekBEgCmmii$vVvoFVWQGBuSF`fs; z9D%4+fjO2f;=@M+=vy+R!46Y0$x@$KoSzROPP5qT-QZ5SLeVGXXH8dXpR5zc_Jm^? ztC_z_R@q!JkzV)~dEC<~hkqeQe)bWc?^cZ-HnoOnX}D8I3fc$q`}>&pJw7T;x+lp2K?Kt{}p)D0}^mDH?=nXTkOgEp_k_$N+1CMXFLD^{hwk#g;^NgtbvDGBen}1 z7(X;%mUOOV%h0D8jHqnt*sP-)2;SsUXdB6gJd>unEH#e;heFs7(t|pv>#isjf_$TROZ$b({?UXA(Jsa6Hn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1q4{_IKs literal 0 HcmV?d00001 diff --git a/exceltesting_test.go b/exceltesting_test.go index ecc33eb..867ce36 100644 --- a/exceltesting_test.go +++ b/exceltesting_test.go @@ -2,7 +2,6 @@ package exceltesting import ( "database/sql" - "github.com/future-architect/go-exceltesting/testonly" "net" "os" "path/filepath" @@ -10,6 +9,8 @@ import ( "testing" "time" + "github.com/future-architect/go-exceltesting/testonly" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/jackc/pgtype" @@ -176,10 +177,11 @@ func Test_exceltesing_Compare(t *testing.T) { mockT := new(testing.T) tests := []struct { - name string - input func(t *testing.T) - wantFile string - equal bool + name string + input func(t *testing.T) + wantFile string + wantSheet string + equal bool }{ { name: "equal", @@ -195,8 +197,9 @@ func Test_exceltesing_Compare(t *testing.T) { t.Fatal(err) } }, - wantFile: filepath.Join("testdata", "compare.xlsx"), - equal: true, + wantFile: filepath.Join("testdata", "compare.xlsx"), + wantSheet: "会社", + equal: true, }, { name: "equal on exceltesing version 2.0 sheet", @@ -212,8 +215,9 @@ func Test_exceltesing_Compare(t *testing.T) { t.Fatal(err) } }, - wantFile: filepath.Join("testdata", "compare_v2.xlsx"), - equal: true, + wantFile: filepath.Join("testdata", "compare_v2.xlsx"), + wantSheet: "会社", + equal: true, }, { name: "diff", @@ -229,8 +233,9 @@ func Test_exceltesing_Compare(t *testing.T) { t.Fatal(err) } }, - wantFile: filepath.Join("testdata", "compare.xlsx"), - equal: false, + wantFile: filepath.Join("testdata", "compare.xlsx"), + wantSheet: "会社", + equal: false, }, { name: "fewer records of results", @@ -246,8 +251,9 @@ func Test_exceltesing_Compare(t *testing.T) { t.Fatal(err) } }, - wantFile: filepath.Join("testdata", "compare.xlsx"), - equal: false, + wantFile: filepath.Join("testdata", "compare.xlsx"), + wantSheet: "会社", + equal: false, }, { name: "many records of results", @@ -263,8 +269,27 @@ func Test_exceltesing_Compare(t *testing.T) { t.Fatal(err) } }, - wantFile: filepath.Join("testdata", "compare.xlsx"), - equal: false, + wantFile: filepath.Join("testdata", "compare.xlsx"), + wantSheet: "会社", + equal: false, + }, + { + name: "partition table", + input: func(t *testing.T) { + t.Helper() + tdb := testonly.OpenTestDB(t) + defer tdb.Close() + if _, err := tdb.Exec(`TRUNCATE temperature;`); err != nil { + t.Fatal(err) + } + if _, err := tdb.Exec(`INSERT INTO temperature (ymd,value) + VALUES ('20210228',-2.0),('20210831',38.5);`); err != nil { + t.Fatal(err) + } + }, + wantFile: filepath.Join("testdata", "compare.xlsx"), + wantSheet: "気温", + equal: true, }, } for _, tt := range tests { @@ -274,7 +299,7 @@ func Test_exceltesing_Compare(t *testing.T) { e := New(conn) got := e.Compare(mockT, CompareRequest{ TargetBookPath: filepath.Join("testdata", "compare.xlsx"), - SheetPrefix: "", + SheetPrefix: tt.wantSheet, IgnoreSheet: nil, IgnoreColumns: []string{"created_at", "updated_at"}, }) diff --git a/query.go b/query.go index 815a86d..b314472 100644 --- a/query.go +++ b/query.go @@ -16,7 +16,7 @@ AND i.oid = ix.indexrelid AND ix.indisprimary = TRUE AND A.attrelid = T.oid AND A.attnum = ANY(ix.indkey) -AND T.relkind = 'r' +AND T.relkind IN ('r', 'p') -- TODO: 将来的には他の relkind にも対応する予定 AND T.relname = ta.tablename AND ta.schemaname = CURRENT_SCHEMA() AND T.relname = $1 diff --git a/testdata/schema/ddl.sql b/testdata/schema/ddl.sql index 9b1bca9..e7c2909 100644 --- a/testdata/schema/ddl.sql +++ b/testdata/schema/ddl.sql @@ -43,3 +43,16 @@ CREATE TABLE test_x( CONSTRAINT test_x_pkc PRIMARY KEY(id) ) ; + +DROP TABLE IF EXISTS temperature +; +CREATE TABLE temperature( + ymd varchar(8) NOT NULL, + value numeric(4,1) NOT NULL, + CONSTRAINT temperature_pkc PRIMARY KEY(ymd) +) PARTITION BY RANGE (ymd) +; +DROP TABLE IF EXISTS temperature_2021_2022 +; +CREATE TABLE temperature_2021_2022 PARTITION OF temperature FOR VALUES FROM ('20210101') TO ('20220101') +;