Skip to content

Commit 3632e63

Browse files
committed
feat: rm temp data
1 parent 174e1bc commit 3632e63

33 files changed

+446
-258
lines changed

\

Lines changed: 0 additions & 23 deletions
This file was deleted.

api/jiaozifs.gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ components:
176176
type: string
177177
allowEmptyValue: true
178178
conflict_resolve:
179-
description: use to record the resolution of the conflict, example({"b/a.txt":"base"})
179+
description: use to record the resolution of the conflict, example({"b/a.txt":"left"})
180180
type: object
181181
additionalProperties:
182182
type: string

controller/wip_ctl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (wipCtl WipController) UpdateWip(ctx context.Context, w *api.JiaozifsRespon
189189

190190
updateParams := models.NewUpdateWipParams(wip.ID)
191191
if body.BaseCommit != nil {
192-
baseCommitHash, err := hash.FromHex(*body.BaseCommit)
192+
baseCommitHash, err := hash.FromHex(utils.StringValue(body.BaseCommit))
193193
if err != nil {
194194
w.Error(err)
195195
return
@@ -205,7 +205,7 @@ func (wipCtl WipController) UpdateWip(ctx context.Context, w *api.JiaozifsRespon
205205
updateParams.SetBaseCommit(baseCommitHash)
206206
}
207207
if body.CurrentTree != nil {
208-
currentTreeHash, err := hash.FromHex(*body.CurrentTree)
208+
currentTreeHash, err := hash.FromHex(utils.StringValue(body.CurrentTree))
209209
if err != nil {
210210
w.Error(err)
211211
return

integrationtest/helper_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ import (
1313
"testing"
1414
"time"
1515

16-
"github.com/jiaozifs/jiaozifs/utils"
17-
1816
"github.com/jiaozifs/jiaozifs/api"
19-
"github.com/smartystreets/goconvey/convey"
20-
21-
"github.com/jiaozifs/jiaozifs/testhelper"
22-
23-
"github.com/stretchr/testify/require"
24-
2517
"github.com/jiaozifs/jiaozifs/cmd"
18+
"github.com/jiaozifs/jiaozifs/testhelper"
19+
"github.com/jiaozifs/jiaozifs/utils"
20+
openapi_types "github.com/oapi-codegen/runtime/types"
2621
"github.com/phayes/freeport"
22+
"github.com/smartystreets/goconvey/convey"
23+
"github.com/stretchr/testify/require"
2724
)
2825

2926
func InitCmd(ctx context.Context, jzHome string, listen string, db string) error {
@@ -57,7 +54,7 @@ func TestDoubleInit(t *testing.T) { //nolint
5754
type Closer func()
5855

5956
func SetupDaemon(t *testing.T, ctx context.Context) (string, Closer) { //nolint
60-
pg, connectString, _ := testhelper.SetupDatabase(ctx, t)
57+
closeDB, connectString, _ := testhelper.SetupDatabase(ctx, t)
6158

6259
port, err := freeport.GetFreePort()
6360
require.NoError(t, err)
@@ -70,7 +67,8 @@ func SetupDaemon(t *testing.T, ctx context.Context) (string, Closer) { //nolint
7067

7168
closer := func() {
7269
cancel()
73-
require.NoError(t, pg.Stop())
70+
require.NoError(t, os.RemoveAll(tmpDir))
71+
closeDB()
7472
}
7573
go func() {
7674
err := Daemon(ctx, buf, tmpDir, url)
@@ -104,12 +102,15 @@ func SetupDaemon(t *testing.T, ctx context.Context) (string, Closer) { //nolint
104102
}
105103
}
106104

105+
var count int
106+
107107
func createUser(ctx context.Context, c convey.C, client *api.Client, userName string) {
108108
c.Convey("register "+userName, func() {
109+
count++
109110
resp, err := client.Register(ctx, api.RegisterJSONRequestBody{
110111
Name: userName,
111112
Password: "12345678",
112-
Email: "mock@gmail.com",
113+
Email: openapi_types.Email(fmt.Sprintf("mock%d@gmail.com", count)),
113114
})
114115
convey.So(err, convey.ShouldBeNil)
115116
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusOK)

integrationtest/merge_request_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,14 @@ func MergeRequestSpec(ctx context.Context, urlStr string) func(c convey.C) {
337337
result, err := api.ParseListMergeRequestsResponse(resp)
338338
convey.So(err, convey.ShouldBeNil)
339339
convey.ShouldHaveLength(*result.JSON200, 2)
340-
if i > 5 {
340+
if i >= 5 {
341341
convey.ShouldBeFalse((*result.JSON200).Pagination.HasMore)
342342
} else {
343343
convey.ShouldBeTrue((*result.JSON200).Pagination.HasMore)
344+
next, err := time.Parse(`2006-01-02 15:04:05.999999999 -0700 MST`, (*result.JSON200).Pagination.NextOffset)
345+
convey.So(err, convey.ShouldBeNil)
346+
after = &next
344347
}
345-
fmt.Println((*result.JSON200).Pagination.NextOffset)
346-
next, err := time.Parse(`2006-01-02 15:04:05.000000 +0800 CST`, (*result.JSON200).Pagination.NextOffset)
347-
convey.So(err, convey.ShouldBeNil)
348-
after = &next
349348
}
350349
})
351350
})

integrationtest/wip_object_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,14 @@ func UpdateWipSpec(ctx context.Context, urlStr string) func(c convey.C) {
471471
loginAndSwitch(ctx, c, client, "jude login", userName, false)
472472
createRepo(ctx, c, client, repoName)
473473
createWip(ctx, c, client, "get wip obj test", userName, repoName, branchName)
474+
475+
//make wip base commit has value
476+
uploadObject(ctx, c, client, "update init object", userName, repoName, branchName, "a.txt")
477+
commitWip(ctx, c, client, "commit init object", userName, repoName, branchName, "test")
478+
474479
uploadObject(ctx, c, client, "update f1 to test branch", userName, repoName, branchName, "m.dat")
475480
uploadObject(ctx, c, client, "update f2 to test branch", userName, repoName, branchName, "g/m.dat")
481+
476482
c.Convey("get wip", func(c convey.C) {
477483
resp, err := client.GetWip(ctx, userName, repoName, &api.GetWipParams{
478484
RefName: branchName,
@@ -535,6 +541,26 @@ func UpdateWipSpec(ctx context.Context, urlStr string) func(c convey.C) {
535541
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
536542
})
537543

544+
c.Convey("update wip with fail base commit", func() {
545+
//delete
546+
resp, err := client.UpdateWip(ctx, userName, repoName, &api.UpdateWipParams{RefName: branchName}, api.UpdateWipJSONRequestBody{
547+
CurrentTree: utils.String(hash.Empty.Hex()),
548+
BaseCommit: utils.String("ddd"),
549+
})
550+
convey.So(err, convey.ShouldBeNil)
551+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusInternalServerError)
552+
})
553+
554+
c.Convey("update wip with fail tree hash", func() {
555+
//delete
556+
resp, err := client.UpdateWip(ctx, userName, repoName, &api.UpdateWipParams{RefName: branchName}, api.UpdateWipJSONRequestBody{
557+
CurrentTree: utils.String("ddd"),
558+
BaseCommit: utils.String(hash.Empty.Hex()),
559+
})
560+
convey.So(err, convey.ShouldBeNil)
561+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusInternalServerError)
562+
})
563+
538564
c.Convey("update wip successful", func() {
539565
//delete
540566
resp, err := client.UpdateWip(ctx, userName, repoName, &api.UpdateWipParams{RefName: branchName}, api.UpdateWipJSONRequestBody{
@@ -555,6 +581,26 @@ func UpdateWipSpec(ctx context.Context, urlStr string) func(c convey.C) {
555581
convey.So((*updatedWip.JSON200).CurrentTree, convey.ShouldEqual, "")
556582
})
557583

584+
c.Convey("fail to update non exit tree hash", func() {
585+
//delete
586+
resp, err := client.UpdateWip(ctx, userName, repoName, &api.UpdateWipParams{RefName: branchName}, api.UpdateWipJSONRequestBody{
587+
CurrentTree: utils.String("6161616161"),
588+
BaseCommit: utils.String(wip.BaseCommit),
589+
})
590+
convey.So(err, convey.ShouldBeNil)
591+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
592+
})
593+
594+
c.Convey("fail to update non exit base commit", func() {
595+
//delete
596+
resp, err := client.UpdateWip(ctx, userName, repoName, &api.UpdateWipParams{RefName: branchName}, api.UpdateWipJSONRequestBody{
597+
CurrentTree: utils.String(wip.CurrentTree),
598+
BaseCommit: utils.String("6161616161"),
599+
})
600+
convey.So(err, convey.ShouldBeNil)
601+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusNotFound)
602+
})
603+
558604
c.Convey("update wip to non empty successful", func() {
559605
//delete
560606
resp, err := client.UpdateWip(ctx, userName, repoName, &api.UpdateWipParams{RefName: branchName}, api.UpdateWipJSONRequestBody{

models/branch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
func TestRefRepoInsert(t *testing.T) {
1717
ctx := context.Background()
18-
postgres, _, db := testhelper.SetupDatabase(ctx, t)
19-
defer postgres.Stop() //nolint
18+
closeDB, _, db := testhelper.SetupDatabase(ctx, t)
19+
defer closeDB()
2020

2121
repo := models.NewBranchRepo(db)
2222

models/commit_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
func TestCommitRepo(t *testing.T) {
1616
ctx := context.Background()
17-
postgres, _, db := testhelper.SetupDatabase(ctx, t)
18-
defer postgres.Stop() //nolint
17+
closeDB, _, db := testhelper.SetupDatabase(ctx, t)
18+
defer closeDB()
1919

2020
repoID := uuid.New()
2121
commitRepo := models.NewCommitRepo(db, repoID)
@@ -41,8 +41,8 @@ func TestCommitRepo(t *testing.T) {
4141

4242
func TestDeleteCommit(t *testing.T) {
4343
ctx := context.Background()
44-
postgres, _, db := testhelper.SetupDatabase(ctx, t)
45-
defer postgres.Stop() //nolint
44+
closeDB, _, db := testhelper.SetupDatabase(ctx, t)
45+
defer closeDB()
4646
t.Run("delete commit", func(t *testing.T) {
4747
repoID := uuid.New()
4848
commitRepo := models.NewCommitRepo(db, repoID)

models/merge_request_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717

1818
func TestMergeRequestRepoInsert(t *testing.T) {
1919
ctx := context.Background()
20-
postgres, _, db := testhelper.SetupDatabase(ctx, t)
21-
defer postgres.Stop() //nolint
20+
closeDB, _, db := testhelper.SetupDatabase(ctx, t)
21+
defer closeDB()
2222

2323
mrRepo := models.NewMergeRequestRepo(db)
2424

0 commit comments

Comments
 (0)