From 00b064929693d9555c615bf344d26bff88da80d1 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 30 Oct 2024 17:10:56 +0800 Subject: [PATCH] Fix the Download Process tests --- widgets/dashboard/process_test.go | 3 +++ widgets/form/process_test.go | 16 ++++++++++++++-- widgets/table/process_test.go | 13 ++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/widgets/dashboard/process_test.go b/widgets/dashboard/process_test.go index 64818f00..8ac38a9c 100644 --- a/widgets/dashboard/process_test.go +++ b/widgets/dashboard/process_test.go @@ -1,6 +1,7 @@ package dashboard import ( + "fmt" "net/url" "testing" @@ -45,6 +46,8 @@ func TestProcessComponent(t *testing.T) { t.Fatal(err) } + fmt.Println(res) + pets, ok := res.([]maps.MapStr) assert.True(t, ok) assert.Equal(t, 2, len(pets)) diff --git a/widgets/form/process_test.go b/widgets/form/process_test.go index e6d240a7..f9f879bc 100644 --- a/widgets/form/process_test.go +++ b/widgets/form/process_test.go @@ -2,6 +2,7 @@ package form import ( "fmt" + "io" "net/url" "os" "testing" @@ -152,7 +153,8 @@ func TestProcessDelete(t *testing.T) { t.Fatal(err) } - _, err = process.New("yao.form.find", "pet", 1).Exec() + res, err := process.New("yao.form.find", "pet", 1).Exec() + fmt.Println("err", res, err) assert.Contains(t, err.Error(), "ID=1") } @@ -251,8 +253,18 @@ func TestProcessDownload(t *testing.T) { } body, ok := res.(map[string]interface{}) + reader, ok := body["content"].(io.ReadCloser) + if !ok { + t.Fatal("content not found") + } + defer reader.Close() + content, err := io.ReadAll(reader) + if err != nil { + t.Fatal(err) + } + assert.True(t, ok) - assert.Equal(t, []byte("Hello"), body["content"]) + assert.Equal(t, []byte("Hello"), content) assert.Equal(t, "text/plain; charset=utf-8", body["type"]) } diff --git a/widgets/table/process_test.go b/widgets/table/process_test.go index d40d52df..1f7c283c 100644 --- a/widgets/table/process_test.go +++ b/widgets/table/process_test.go @@ -2,6 +2,7 @@ package table import ( "fmt" + "io" "net/url" "os" "testing" @@ -451,8 +452,18 @@ func TestProcessDownload(t *testing.T) { } body, ok := res.(map[string]interface{}) + reader, ok := body["content"].(io.ReadCloser) + if !ok { + t.Fatal("content not found") + } + defer reader.Close() + content, err := io.ReadAll(reader) + if err != nil { + t.Fatal(err) + } + assert.True(t, ok) - assert.Equal(t, []byte("Hello"), body["content"]) + assert.Equal(t, []byte("Hello"), content) assert.Equal(t, "text/plain; charset=utf-8", body["type"]) }