package file import ( "github.com/go-pg/pg/v10" "net/http" "github.com/gavv/httpexpect" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" pG "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" ) var _ = Describe("返回文件服务列表", func() { var fileId int64 BeforeEach(func() { _, err := pG.DB.QueryOne( pg.Scan(&fileId), "INSERT INTO files (file_id, file_type, file_info, source_file_id, operator, created_at, updated_at, deleted_at, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING file_id", "testFileId", "testFileType", "testFileInfo", "testSourceFileId", "testOperator", "testCreatedAt", "testUpdatedAt", "testDeletedAt", "testVersion") Expect(err).NotTo(HaveOccurred()) }) Describe("根据参数返回文件列表", func() { Context("传入有效的参数", func() { It("返回文件数据列表", func() { httpExpect := httpexpect.New(GinkgoT(), server.URL) httpExpect.GET("/files/"). WithQuery("offset", "int"). WithQuery("limit", "int"). Expect(). Status(http.StatusOK). JSON(). Object(). ContainsKey("code").ValueEqual("code", 0). ContainsKey("msg").ValueEqual("msg", "ok"). ContainsKey("data").Value("data").Object(). ContainsKey("count").ValueEqual("count", 1). ContainsKey("files").Value("files").Array() }) }) }) AfterEach(func() { _, err := pG.DB.Exec("DELETE FROM files WHERE true") Expect(err).NotTo(HaveOccurred()) }) })