This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsyncher_test.go
More file actions
82 lines (70 loc) · 1.78 KB
/
syncher_test.go
File metadata and controls
82 lines (70 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package sync
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/hanjunlee/gitploy/ent"
"github.com/hanjunlee/gitploy/internal/server/api/v1/sync/mock"
"github.com/hanjunlee/gitploy/internal/server/global"
"github.com/hanjunlee/gitploy/vo"
)
func TestSyncher_Sync(t *testing.T) {
ctx := gomock.Any()
t.Run("Synchronize with remote repositories", func(t *testing.T) {
ctrl := gomock.NewController(t)
m := mock.NewMockInteractor(ctrl)
t.Log("List remote repositories")
m.
EXPECT().
ListRemoteRepos(ctx, gomock.AssignableToTypeOf(&ent.User{})).
Return([]*vo.RemoteRepo{
{
ID: "1",
Namespace: "octocat",
Name: "HelloWorld",
},
{
ID: "1",
Namespace: "cat",
Name: "GoodBye",
},
}, nil)
t.Log("Only octocat is trusted namespace.")
m.
EXPECT().
IsEntryOrg(ctx, gomock.Any()).
DoAndReturn(func(ctx context.Context, namespace string) bool {
return namespace == "octocat"
}).
AnyTimes()
t.Log("Sync with HelloWorld only.")
m.
EXPECT().
SyncRemoteRepo(ctx, gomock.Any(), gomock.Eq(&vo.RemoteRepo{
ID: "1",
Namespace: "octocat",
Name: "HelloWorld",
})).
Return(nil)
t.Log("Delete staled perms.")
m.
EXPECT().
DeletePermsOfUserLessThanUpdatedAt(ctx, gomock.Any(), gomock.Any()).
Return(0, nil)
gin.SetMode(gin.ReleaseMode)
router := gin.New()
s := NewSyncher(m)
router.POST("/sync", func(c *gin.Context) {
c.Set(global.KeyUser, &ent.User{})
}, s.Sync)
req, _ := http.NewRequest("POST", "/sync", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("Sync = %v, wanted %v", w.Code, http.StatusOK)
}
})
}