mirror of https://github.com/artifacthub/hub.git
Parallelize backend tests (#937)
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
This commit is contained in:
parent
d7e765c90e
commit
219d9b43d2
|
|
@ -60,6 +60,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.akJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -79,6 +80,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error adding api key", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(akJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -94,6 +96,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("api key added successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(akJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -141,6 +144,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -159,6 +163,7 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("delete api key succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -200,6 +205,7 @@ func TestGet(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -218,6 +224,7 @@ func TestGet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("api key get succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -241,6 +248,7 @@ func TestGet(t *testing.T) {
|
|||
|
||||
func TestGetOwnedByUser(t *testing.T) {
|
||||
t.Run("error getting api keys owned by user", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -256,6 +264,7 @@ func TestGetOwnedByUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get api keys owned by user succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -302,6 +311,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(tc.akJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -346,6 +356,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", bytes.NewReader(akJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ func TestRealIP(t *testing.T) {
|
|||
tc := tc
|
||||
desc := fmt.Sprintf("XFF: %s Index: %d", tc.xForwardedFor, tc.xffIndex)
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r := &http.Request{
|
||||
RemoteAddr: "1.1.1.1:",
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ func TestBuildCacheControlHeader(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cacheControlHeader := BuildCacheControlHeader(tc.cacheMaxAge)
|
||||
assert.Equal(t, tc.expectedCacheControlHeader, cacheControlHeader)
|
||||
})
|
||||
|
|
@ -67,6 +68,7 @@ func TestRenderJSON(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
RenderJSON(w, tc.data, tc.cacheMaxAge, tc.code)
|
||||
resp := w.Result()
|
||||
|
|
@ -121,6 +123,7 @@ func TestRenderErrorJSON(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
RenderErrorJSON(w, tc.err)
|
||||
resp := w.Result()
|
||||
|
|
@ -162,6 +165,7 @@ func TestRenderErrorWithCodeJSON(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
RenderErrorWithCodeJSON(w, tc.err, tc.code)
|
||||
resp := w.Result()
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.orgJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -107,6 +108,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(orgJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -153,6 +155,7 @@ func TestAddMember(t *testing.T) {
|
|||
desc = tc.omErr.Error()
|
||||
}
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -178,6 +181,7 @@ func TestAddMember(t *testing.T) {
|
|||
|
||||
func TestCheckAvailability(t *testing.T) {
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -215,6 +219,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("resource kind: %s", tc.resourceKind), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -244,6 +249,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("check availability failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -292,6 +298,7 @@ func TestConfirmMembership(t *testing.T) {
|
|||
desc = tc.omErr.Error()
|
||||
}
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -344,6 +351,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
desc = tc.omErr.Error()
|
||||
}
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -392,6 +400,7 @@ func TestGet(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.omErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -410,6 +419,7 @@ func TestGet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get organization succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -456,6 +466,7 @@ func TestGetAuthorizationPolicy(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.omErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -474,6 +485,7 @@ func TestGetAuthorizationPolicy(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get authorization policy succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -497,6 +509,7 @@ func TestGetAuthorizationPolicy(t *testing.T) {
|
|||
|
||||
func TestGetByUser(t *testing.T) {
|
||||
t.Run("get user organizations succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -517,6 +530,7 @@ func TestGetByUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting user organizations", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -557,6 +571,7 @@ func TestGetMembers(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.omErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -575,6 +590,7 @@ func TestGetMembers(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get organization members succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -622,6 +638,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(tc.orgJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -675,6 +692,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(orgJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -732,6 +750,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(tc.policyJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -787,6 +806,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(policyJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -820,6 +840,7 @@ func TestGetUserAllowedActions(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("get allowed actions failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -836,6 +857,7 @@ func TestGetUserAllowedActions(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get allowed actions succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ func TestGet(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.pmErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -66,6 +67,7 @@ func TestGet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get package succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -95,6 +97,7 @@ func TestGetChangeLog(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("get changelog succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -115,6 +118,7 @@ func TestGetChangeLog(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting changelog", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -132,6 +136,7 @@ func TestGetChangeLog(t *testing.T) {
|
|||
|
||||
func TestGetRandom(t *testing.T) {
|
||||
t.Run("get random packages succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -151,6 +156,7 @@ func TestGetRandom(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting random packages", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -174,6 +180,7 @@ func TestGetSnapshotSecurityReport(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("get snapshot security report succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -194,6 +201,7 @@ func TestGetSnapshotSecurityReport(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting snapshot security report", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -211,6 +219,7 @@ func TestGetSnapshotSecurityReport(t *testing.T) {
|
|||
|
||||
func TestGetStarredByUser(t *testing.T) {
|
||||
t.Run("get packages starred by user succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -231,6 +240,7 @@ func TestGetStarredByUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting packages starred by user", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -271,6 +281,7 @@ func TestGetStars(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -289,6 +300,7 @@ func TestGetStars(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get stars succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -312,6 +324,7 @@ func TestGetStars(t *testing.T) {
|
|||
|
||||
func TestGetStats(t *testing.T) {
|
||||
t.Run("get stats succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -331,6 +344,7 @@ func TestGetStats(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting stats", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -354,6 +368,7 @@ func TestGetValuesSchema(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("get values schema succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -374,6 +389,7 @@ func TestGetValuesSchema(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting values schema", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -441,6 +457,7 @@ func TestInjectIndexMeta(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -484,6 +501,7 @@ func TestRssFeed(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.pmErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -565,6 +583,7 @@ func TestRssFeed(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -605,6 +624,7 @@ func TestSearch(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("%s: %s", tc.desc, tc.params), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/?"+tc.params, nil)
|
||||
|
||||
|
|
@ -619,6 +639,7 @@ func TestSearch(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid search input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -632,6 +653,7 @@ func TestSearch(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("valid request, search succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -651,6 +673,7 @@ func TestSearch(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error searching packages", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -667,6 +690,7 @@ func TestSearch(t *testing.T) {
|
|||
|
||||
func TestSearchMonocular(t *testing.T) {
|
||||
t.Run("search succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/?q=text", nil)
|
||||
|
||||
|
|
@ -686,6 +710,7 @@ func TestSearchMonocular(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("search failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/?q=text", nil)
|
||||
|
||||
|
|
@ -725,6 +750,7 @@ func TestToggleStar(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -743,6 +769,7 @@ func TestToggleStar(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("toggle star succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.repoJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -113,6 +114,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(repoJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -133,6 +135,7 @@ func TestAdd(t *testing.T) {
|
|||
|
||||
func TestBadge(t *testing.T) {
|
||||
t.Run("badge info returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -160,6 +163,7 @@ func TestBadge(t *testing.T) {
|
|||
|
||||
func TestCheckAvailability(t *testing.T) {
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -200,6 +204,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("resource kind: %s", tc.resourceKind), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -230,6 +235,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("check availability failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -255,6 +261,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
|
||||
func TestClaimOwnership(t *testing.T) {
|
||||
t.Run("invalid input - missing repo name", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -294,6 +301,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/?org=org1", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -327,6 +335,7 @@ func TestDelete(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("delete repository succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -363,6 +372,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.rmErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -383,6 +393,7 @@ func TestDelete(t *testing.T) {
|
|||
|
||||
func TestGetAll(t *testing.T) {
|
||||
t.Run("get all repositories succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -403,6 +414,7 @@ func TestGetAll(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting all repositories", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -427,6 +439,7 @@ func TestGetByKind(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("invalid kind provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -441,6 +454,7 @@ func TestGetByKind(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get repositories by kind succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -462,6 +476,7 @@ func TestGetByKind(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting repositories by kind", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -487,6 +502,7 @@ func TestGetOwnedByOrg(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("get repositories owned by organization succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -524,6 +540,7 @@ func TestGetOwnedByOrg(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.rmErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -544,6 +561,7 @@ func TestGetOwnedByOrg(t *testing.T) {
|
|||
|
||||
func TestGetOwnedByUser(t *testing.T) {
|
||||
t.Run("get repositories owned by user succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -564,6 +582,7 @@ func TestGetOwnedByUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting repositories owned by user", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -581,6 +600,7 @@ func TestGetOwnedByUser(t *testing.T) {
|
|||
|
||||
func TestTransfer(t *testing.T) {
|
||||
t.Run("invalid input - missing repo name", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -620,6 +640,7 @@ func TestTransfer(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/?org=org1", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -670,6 +691,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(tc.repoJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -722,6 +744,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(repoJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ func TestImage(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("non existing image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -51,6 +52,7 @@ func TestImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("other internal error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
|
||||
|
|
@ -77,6 +79,7 @@ func TestImage(t *testing.T) {
|
|||
i := i
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("Test %d: %s", i, tc.expectedContentType), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
imgData, err := ioutil.ReadFile(tc.imgPath)
|
||||
require.NoError(t, err)
|
||||
w := httptest.NewRecorder()
|
||||
|
|
@ -105,6 +108,7 @@ func TestSaveImage(t *testing.T) {
|
|||
fakeSaveImageError := errors.New("fake save image error")
|
||||
|
||||
t.Run("imageStore.SaveImage failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader("imageData"))
|
||||
|
||||
|
|
@ -119,6 +123,7 @@ func TestSaveImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("imageStore.SaveImage succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader("imageData"))
|
||||
|
||||
|
|
@ -139,6 +144,7 @@ func TestSaveImage(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestServeIndex(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.subscriptionJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -98,6 +99,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(subscriptionJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -141,6 +143,7 @@ func TestAddOptOut(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.optOutJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -188,6 +191,7 @@ func TestAddOptOut(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(optOutJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -241,6 +245,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/?"+tc.qsParams, nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -285,6 +290,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/?"+qs, nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -330,6 +336,7 @@ func TestDeleteOptOut(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -372,6 +379,7 @@ func TestGetByPackage(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.smErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -390,6 +398,7 @@ func TestGetByPackage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get package subscriptions succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -413,6 +422,7 @@ func TestGetByPackage(t *testing.T) {
|
|||
|
||||
func TestGetByUser(t *testing.T) {
|
||||
t.Run("error getting user subscriptions", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -428,6 +438,7 @@ func TestGetByUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get user subscriptions succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -450,6 +461,7 @@ func TestGetByUser(t *testing.T) {
|
|||
|
||||
func TestGetOptOutList(t *testing.T) {
|
||||
t.Run("error getting user opt-out entries", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -465,6 +477,7 @@ func TestGetOptOutList(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get user opt-out entries succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ func TestBasicAuth(t *testing.T) {
|
|||
hw.cfg.Set("server.basicAuth.password", "test")
|
||||
|
||||
t.Run("without basic auth credentials", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
hw.h.BasicAuth(http.HandlerFunc(testsOK)).ServeHTTP(w, r)
|
||||
|
|
@ -47,6 +48,7 @@ func TestBasicAuth(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("with basic auth credentials", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.SetBasicAuth("test", "test")
|
||||
|
|
@ -60,6 +62,7 @@ func TestBasicAuth(t *testing.T) {
|
|||
|
||||
func TestCheckAvailability(t *testing.T) {
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -97,6 +100,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("resource kind: %s", tc.resourceKind), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -126,6 +130,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("check availability failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("HEAD", "/?v=value", nil)
|
||||
rctx := &chi.Context{
|
||||
|
|
@ -150,6 +155,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
|
||||
func TestGetProfile(t *testing.T) {
|
||||
t.Run("error getting profile", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -165,6 +171,7 @@ func TestGetProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("profile get succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -197,6 +204,7 @@ func TestInjectUserID(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("session cookie not provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -209,6 +217,7 @@ func TestInjectUserID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid session cookie provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.AddCookie(&http.Cookie{
|
||||
|
|
@ -225,6 +234,7 @@ func TestInjectUserID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error checking session", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -245,6 +255,7 @@ func TestInjectUserID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid session provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -266,6 +277,7 @@ func TestInjectUserID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("inject user id succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -288,6 +300,7 @@ func TestInjectUserID(t *testing.T) {
|
|||
|
||||
func TestLogin(t *testing.T) {
|
||||
t.Run("invalid", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"email": "email" ...`)
|
||||
r, _ := http.NewRequest("POST", "/", body)
|
||||
|
|
@ -301,6 +314,7 @@ func TestLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("credentials not provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{}`)
|
||||
r, _ := http.NewRequest("POST", "/", body)
|
||||
|
|
@ -315,6 +329,7 @@ func TestLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error checking credentials", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"email": "email", "password": "pass"}`)
|
||||
r, _ := http.NewRequest("POST", "/", body)
|
||||
|
|
@ -330,6 +345,7 @@ func TestLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid credentials provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"email": "email", "password": "pass2"}`)
|
||||
r, _ := http.NewRequest("POST", "/", body)
|
||||
|
|
@ -346,6 +362,7 @@ func TestLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error registering session", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"email": "email", "password": "pass"}`)
|
||||
r, _ := http.NewRequest("POST", "/", body)
|
||||
|
|
@ -364,6 +381,7 @@ func TestLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("login succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"email": "email", "password": "pass"}`)
|
||||
r, _ := http.NewRequest("POST", "/", body)
|
||||
|
|
@ -413,6 +431,7 @@ func TestLogout(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
if tc.cookie != nil {
|
||||
|
|
@ -450,6 +469,7 @@ func TestLogout(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -477,6 +497,7 @@ func TestLogout(t *testing.T) {
|
|||
|
||||
func TestRegisterUser(t *testing.T) {
|
||||
t.Run("no user provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(""))
|
||||
|
||||
|
|
@ -518,6 +539,7 @@ func TestRegisterUser(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.userJSON))
|
||||
|
||||
|
|
@ -567,6 +589,7 @@ func TestRegisterUser(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(userJSON))
|
||||
|
||||
|
|
@ -588,6 +611,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
|
||||
t.Run("session cookie based authentication", func(t *testing.T) {
|
||||
t.Run("invalid session cookie provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.AddCookie(&http.Cookie{
|
||||
|
|
@ -604,6 +628,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error checking session", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -624,6 +649,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid session provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -644,6 +670,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("session cookie based authentication succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -669,6 +696,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
keyB64 := base64.StdEncoding.EncodeToString(key)
|
||||
|
||||
t.Run("invalid api key provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.Header.Add(apiKeyHeader, "invalidB64")
|
||||
|
|
@ -682,6 +710,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error checking api key", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.Header.Add(apiKeyHeader, keyB64)
|
||||
|
|
@ -697,6 +726,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid api key provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.Header.Add(apiKeyHeader, keyB64)
|
||||
|
|
@ -713,6 +743,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("api key based authentication succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r.Header.Add(apiKeyHeader, keyB64)
|
||||
|
|
@ -730,6 +761,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no authentication method used", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
|
|
@ -744,6 +776,7 @@ func TestRequireLogin(t *testing.T) {
|
|||
|
||||
func TestUpdatePassword(t *testing.T) {
|
||||
t.Run("no old password provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"new": "new"}`)
|
||||
r, _ := http.NewRequest("PUT", "/", body)
|
||||
|
|
@ -759,6 +792,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no new password provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"old": "old"}`)
|
||||
r, _ := http.NewRequest("PUT", "/", body)
|
||||
|
|
@ -774,6 +808,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid old password provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"old": "invalid", "new": "new"}`)
|
||||
r, _ := http.NewRequest("PUT", "/", body)
|
||||
|
|
@ -791,6 +826,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error updating password", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"old": "old", "new": "new"}`)
|
||||
r, _ := http.NewRequest("PUT", "/", body)
|
||||
|
|
@ -808,6 +844,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("password updated successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
body := strings.NewReader(`{"old": "old", "new": "new"}`)
|
||||
r, _ := http.NewRequest("PUT", "/", body)
|
||||
|
|
@ -854,6 +891,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(tc.userJSON))
|
||||
|
||||
|
|
@ -872,6 +910,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error updating profile", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(userJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -887,6 +926,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("user profile updated successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(userJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -932,6 +972,7 @@ func TestVerifyEmail(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(`{"code": "1234"}`))
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.webhookJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -118,6 +119,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(webhookJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -165,6 +167,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -183,6 +186,7 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("delete webhook succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("DELETE", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -228,6 +232,7 @@ func TestGet(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -246,6 +251,7 @@ func TestGet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("webhook get succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -276,6 +282,7 @@ func TestGetOwnedByOrg(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("get webhooks owned by organization succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -313,6 +320,7 @@ func TestGetOwnedByOrg(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -333,6 +341,7 @@ func TestGetOwnedByOrg(t *testing.T) {
|
|||
|
||||
func TestGetOwnedByUser(t *testing.T) {
|
||||
t.Run("error getting webhooks owned by user", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -348,6 +357,7 @@ func TestGetOwnedByUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get webhook owned by user succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("GET", "/", nil)
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -386,6 +396,7 @@ func TestTriggerTest(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.webhookJSON))
|
||||
|
||||
|
|
@ -426,6 +437,7 @@ func TestTriggerTest(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.err, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("POST", "/", strings.NewReader(tc.webhookJSON))
|
||||
|
||||
|
|
@ -442,6 +454,7 @@ func TestTriggerTest(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error calling webhook endpoint", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
webhookJSON := `
|
||||
{
|
||||
"name": "webhook1",
|
||||
|
|
@ -463,6 +476,7 @@ func TestTriggerTest(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("received unexpected status code", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
|
|
@ -530,6 +544,7 @@ func TestTriggerTest(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.id, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
contentType := tc.contentType
|
||||
if contentType == "" {
|
||||
|
|
@ -591,6 +606,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(tc.webhookJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
@ -648,6 +664,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
w := httptest.NewRecorder()
|
||||
r, _ := http.NewRequest("PUT", "/", strings.NewReader(webhookJSON))
|
||||
r = r.WithContext(context.WithValue(r.Context(), hub.UserIDKey, "userID"))
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ const apiKeyID = "00000000-0000-0000-0000-000000000001"
|
|||
|
||||
func TestAdd(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
ak := &hub.APIKey{
|
||||
Name: "apikey1",
|
||||
UserID: "userID",
|
||||
}
|
||||
akJSON, _ := json.Marshal(ak)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.Add(context.Background(), ak)
|
||||
})
|
||||
})
|
||||
|
|
@ -43,6 +43,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
|
||||
dataJSON, err := m.Add(ctx, tc.ak)
|
||||
|
|
@ -54,6 +55,12 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ak := &hub.APIKey{
|
||||
Name: "apikey1",
|
||||
UserID: "userID",
|
||||
}
|
||||
akJSON, _ := json.Marshal(ak)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, addAPIKeyDBQ, akJSON).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -65,6 +72,12 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("add api key succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ak := &hub.APIKey{
|
||||
Name: "apikey1",
|
||||
UserID: "userID",
|
||||
}
|
||||
akJSON, _ := json.Marshal(ak)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, addAPIKeyDBQ, akJSON).Return([]byte("key"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -80,6 +93,7 @@ func TestDelete(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Delete(context.Background(), apiKeyID)
|
||||
|
|
@ -87,12 +101,14 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.Delete(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteAPIKeyDBQ, "userID", apiKeyID).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -103,6 +119,7 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("delete api key succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteAPIKeyDBQ, "userID", apiKeyID).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -117,6 +134,7 @@ func TestGetJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetJSON(context.Background(), apiKeyID)
|
||||
|
|
@ -124,12 +142,14 @@ func TestGetJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
_, err := m.GetJSON(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAPIKeyDBQ, "userID", apiKeyID).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -141,6 +161,7 @@ func TestGetJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("api key data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAPIKeyDBQ, "userID", apiKeyID).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -156,6 +177,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetOwnedByUserJSON(context.Background())
|
||||
|
|
@ -163,6 +185,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAPIKeysDBQ, "userID").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -174,6 +197,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("user api keys data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAPIKeysDBQ, "userID").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -187,16 +211,16 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
|
||||
func TestUpdate(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
ak := &hub.APIKey{
|
||||
APIKeyID: apiKeyID,
|
||||
Name: "apikey1-updated",
|
||||
UserID: "userID",
|
||||
}
|
||||
akJSON, _ := json.Marshal(ak)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Update(context.Background(), ak)
|
||||
})
|
||||
})
|
||||
|
|
@ -223,6 +247,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
|
||||
err := m.Update(ctx, tc.ak)
|
||||
|
|
@ -233,6 +258,13 @@ func TestUpdate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ak := &hub.APIKey{
|
||||
APIKeyID: apiKeyID,
|
||||
Name: "apikey1-updated",
|
||||
UserID: "userID",
|
||||
}
|
||||
akJSON, _ := json.Marshal(ak)
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateAPIKeyDBQ, akJSON).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -243,6 +275,13 @@ func TestUpdate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("update api key succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ak := &hub.APIKey{
|
||||
APIKeyID: apiKeyID,
|
||||
Name: "apikey1-updated",
|
||||
UserID: "userID",
|
||||
}
|
||||
akJSON, _ := json.Marshal(ak)
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateAPIKeyDBQ, akJSON).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ func TestMain(m *testing.M) {
|
|||
|
||||
func TestNewAuthorizer(t *testing.T) {
|
||||
t.Run("error getting authorization policies", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", context.Background(), getAuthzPoliciesDBQ).Return(nil, tests.ErrFakeDB)
|
||||
db.On("Acquire", context.Background()).Return(nil, tests.ErrFakeDB).Maybe()
|
||||
|
|
@ -89,6 +90,7 @@ func TestNewAuthorizer(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error unmarshalling authorization policies", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", context.Background(), getAuthzPoliciesDBQ).Return([]byte(`{"invalid`), nil)
|
||||
db.On("Acquire", context.Background()).Return(nil, tests.ErrFakeDB).Maybe()
|
||||
|
|
@ -98,6 +100,7 @@ func TestNewAuthorizer(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorizer created successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", context.Background(), getAuthzPoliciesDBQ).Return(testsAuthorizationPoliciesJSON, nil)
|
||||
db.On("Acquire", context.Background()).Return(nil, tests.ErrFakeDB).Maybe()
|
||||
|
|
@ -231,6 +234,7 @@ func TestAuthorize(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := az.Authorize(context.Background(), tc.input)
|
||||
if tc.allow {
|
||||
assert.Nil(t, err)
|
||||
|
|
@ -320,6 +324,7 @@ func TestGetAllowedActions(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
allowedActions, _ := az.GetAllowedActions(context.Background(), tc.userID, tc.orgName)
|
||||
assert.Equal(t, tc.expectedAllowedActions, allowedActions)
|
||||
})
|
||||
|
|
@ -457,6 +462,7 @@ func TestWillUserBeLockedOut(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
policyDataJSON, _ := json.Marshal(tc.policyData)
|
||||
p := &hub.AuthorizationPolicy{
|
||||
PredefinedPolicy: tc.predefinedPolicy,
|
||||
|
|
@ -492,6 +498,7 @@ func TestIsPredefinedPolicyValid(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
valid := IsPredefinedPolicyValid(tc.predefinedPolicy)
|
||||
assert.Equal(t, tc.expectedValid, valid)
|
||||
})
|
||||
|
|
@ -533,6 +540,7 @@ func TestIsActionAllowed(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
allowed := IsActionAllowed(tc.allowedActions, tc.action)
|
||||
assert.Equal(t, tc.expectedAllowed, allowed)
|
||||
})
|
||||
|
|
@ -579,6 +587,7 @@ func TestAreActionsAllowed(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
allowed := AreActionsAllowed(tc.allowedActions, tc.actions)
|
||||
assert.Equal(t, tc.expectedAllowed, allowed)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func TestDispatcher(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup dispatcher
|
||||
d := NewDispatcher(&Services{}, WithNumWorkers(0))
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ func TestGetPending(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tx := &tests.TXMock{}
|
||||
tx.On("QueryRow", ctx, getPendingEventDBQ).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager()
|
||||
|
|
@ -32,6 +33,7 @@ func TestGetPending(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedEvent := &hub.Event{
|
||||
EventID: "00000000-0000-0000-0000-000000000001",
|
||||
PackageVersion: "1.0.0",
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ func TestWorker(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("error getting pending event", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(nil, tests.ErrFake)
|
||||
|
|
@ -45,6 +46,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting subscriptors", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -57,6 +59,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no subscriptors nor webhooks found", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -70,6 +73,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error adding email notification", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -83,6 +87,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("adding one email notification succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -97,6 +102,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("adding two email notifications succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -112,6 +118,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error adding webhook notification", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -126,6 +133,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("adding one webhook notification succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
@ -140,6 +148,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("adding two webhook notifications succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.em.On("GetPending", sw.ctx, sw.tx).Return(e, nil)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import (
|
|||
var update = flag.Bool("update", false, "Write image versions to testdata directory")
|
||||
|
||||
func TestGenerateImageVersions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Read sample images
|
||||
validImgData, err := ioutil.ReadFile("testdata/valid.png")
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestNewImageStore(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
s := NewImageStore(db)
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ func TestGetImage(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("existing image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageDBQ, "imageID", "2x").Return([]byte("image2xData"), nil)
|
||||
s := NewImageStore(db)
|
||||
|
|
@ -36,6 +38,7 @@ func TestGetImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageDBQ, "imageID", "2x").Return(nil, tests.ErrFakeDB)
|
||||
s := NewImageStore(db)
|
||||
|
|
@ -59,6 +62,7 @@ func TestSaveImage(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("successful png image registration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageIDDBQ, pngImgHash).Return(nil, pgx.ErrNoRows)
|
||||
for _, version := range []string{"1x", "2x", "3x", "4x"} {
|
||||
|
|
@ -73,6 +77,7 @@ func TestSaveImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("successful svg image registration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageIDDBQ, svgImgHash).Return(nil, pgx.ErrNoRows)
|
||||
db.On("QueryRow", ctx, registerImageDBQ, svgImgHash, "svg", mock.Anything).Return("svgImgID", nil)
|
||||
|
|
@ -85,6 +90,7 @@ func TestSaveImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("try to register existing png image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageIDDBQ, pngImgHash).Return("existingImageID", nil)
|
||||
s := NewImageStore(db)
|
||||
|
|
@ -96,6 +102,7 @@ func TestSaveImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error calling get_image_id", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageIDDBQ, pngImgHash).Return(nil, tests.ErrFakeDB)
|
||||
s := NewImageStore(db)
|
||||
|
|
@ -107,6 +114,7 @@ func TestSaveImage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error calling register_image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getImageIDDBQ, pngImgHash).Return(nil, pgx.ErrNoRows)
|
||||
db.On("QueryRow", ctx, registerImageDBQ, pngImgHash, "1x", mock.Anything).Return(nil, tests.ErrFakeDB)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import (
|
|||
)
|
||||
|
||||
func TestDispatcher(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup dispatcher
|
||||
cfg := viper.New()
|
||||
cfg.Set("server.baseURL", "http://localhost:8000")
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager()
|
||||
err := m.Add(context.Background(), nil, tc.n)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -81,6 +82,7 @@ func TestAdd(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tx := &tests.TXMock{}
|
||||
tx.On("Exec", ctx, addNotificationDBQ, mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager()
|
||||
|
|
@ -91,6 +93,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tx := &tests.TXMock{}
|
||||
tx.On("Exec", ctx, addNotificationDBQ, mock.Anything).Return(nil)
|
||||
m := NewManager()
|
||||
|
|
@ -105,6 +108,7 @@ func TestGetPending(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tx := &tests.TXMock{}
|
||||
tx.On("QueryRow", ctx, getPendingNotificationDBQ).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager()
|
||||
|
|
@ -116,6 +120,7 @@ func TestGetPending(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedNotification := &hub.Notification{
|
||||
NotificationID: "notificationID",
|
||||
Event: &hub.Event{
|
||||
|
|
@ -168,6 +173,7 @@ func TestUpdateStatus(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager()
|
||||
err := m.UpdateStatus(ctx, nil, "invalidNotificationID", false, nil)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -177,6 +183,7 @@ func TestUpdateStatus(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tx := &tests.TXMock{}
|
||||
tx.On("Exec", ctx, updateNotificationStatusDBQ, notificationID, true, "").Return(tests.ErrFakeDB)
|
||||
m := NewManager()
|
||||
|
|
@ -187,6 +194,7 @@ func TestUpdateStatus(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tx := &tests.TXMock{}
|
||||
tx.On("Exec", ctx, updateNotificationStatusDBQ, notificationID, true, "").Return(nil)
|
||||
m := NewManager()
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ func TestWorker(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("error getting pending notification", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(nil, tests.ErrFake)
|
||||
|
|
@ -87,6 +88,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting package preparing email data", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n1, nil)
|
||||
|
|
@ -99,6 +101,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting repository preparing email data", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n3, nil)
|
||||
|
|
@ -111,6 +114,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error sending package notification email", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n1, nil)
|
||||
|
|
@ -125,6 +129,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error sending repository notification email", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n3, nil)
|
||||
|
|
@ -139,6 +144,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package email notification delivered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n1, nil)
|
||||
|
|
@ -153,6 +159,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("repository email notification delivered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n3, nil)
|
||||
|
|
@ -167,6 +174,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting package preparing webhook payload", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n2, nil)
|
||||
|
|
@ -179,6 +187,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("webhook call returned an error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n2, nil)
|
||||
|
|
@ -193,6 +202,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("webhook call returned an unexpected status code", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n2, nil)
|
||||
|
|
@ -210,6 +220,7 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("webhook notification delivered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sw := newServicesWrapper()
|
||||
sw.db.On("Begin", sw.ctx).Return(sw.tx, nil)
|
||||
sw.nm.On("GetPending", sw.ctx, sw.tx).Return(n2, nil)
|
||||
|
|
@ -272,6 +283,7 @@ func TestWorker(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.id, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
contentType := tc.contentType
|
||||
if contentType == "" {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ func TestAdd(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Add(context.Background(), &hub.Organization{})
|
||||
|
|
@ -59,6 +60,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
err := m.Add(ctx, tc.org)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -68,6 +70,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addOrgDBQ, "userID", mock.Anything).Return(nil)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -78,6 +81,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addOrgDBQ, "userID", mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -92,6 +96,7 @@ func TestAddMember(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.AddMember(context.Background(), "orgName", "userAlias", "")
|
||||
|
|
@ -133,6 +138,7 @@ func TestAddMember(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
err := m.AddMember(ctx, tc.orgName, tc.userAlias, tc.baseURL)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -142,6 +148,7 @@ func TestAddMember(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
az := &authz.AuthorizerMock{}
|
||||
az.On("Authorize", ctx, &hub.AuthorizeInput{
|
||||
OrganizationName: "orgName",
|
||||
|
|
@ -172,6 +179,7 @@ func TestAddMember(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addOrgMemberDBQ, "userID", "orgName", "userAlias").Return(nil)
|
||||
db.On("QueryRow", ctx, getUserEmailDBQ, mock.Anything).Return("email", nil)
|
||||
|
|
@ -211,6 +219,7 @@ func TestAddMember(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addOrgMemberDBQ, "userID", "orgName", "userAlias").Return(tc.dbErr)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -253,6 +262,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
_, err := m.CheckAvailability(context.Background(), tc.resourceKind, tc.value)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -276,6 +286,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("resource kind: %s", tc.resourceKind), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tc.dbQuery = fmt.Sprintf("select not exists (%s)", tc.dbQuery)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, tc.dbQuery, "value").Return(tc.available, nil)
|
||||
|
|
@ -290,6 +301,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
dbQuery := fmt.Sprintf(`select not exists (%s)`, checkOrgNameAvailDBQ)
|
||||
db.On("QueryRow", ctx, dbQuery, "value").Return(false, tests.ErrFakeDB)
|
||||
|
|
@ -306,6 +318,7 @@ func TestConfirmMembership(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.ConfirmMembership(context.Background(), "orgName")
|
||||
|
|
@ -313,12 +326,14 @@ func TestConfirmMembership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
err := m.ConfirmMembership(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, confirmMembershipDBQ, "userID", "orgName").Return(nil)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -329,6 +344,7 @@ func TestConfirmMembership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, confirmMembershipDBQ, "userID", "orgName").Return(tests.ErrFakeDB)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -343,6 +359,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.DeleteMember(context.Background(), "orgName", "userAlias")
|
||||
|
|
@ -369,6 +386,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
err := m.DeleteMember(ctx, tc.orgName, tc.userAlias)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -378,6 +396,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get requesting user alias failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAliasDBQ, "userID").Return("", tests.ErrFakeDB)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -388,6 +407,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAliasDBQ, "userID").Return("requestingUserAlias", nil)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -404,6 +424,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("member deleted successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAliasDBQ, "userID").Return("requestingUserAlias", nil)
|
||||
db.On("Exec", ctx, deleteOrgMemberDBQ, "userID", "orgName", "userAlias").Return(nil)
|
||||
|
|
@ -422,6 +443,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("user left organization successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAliasDBQ, "userID").Return("userAlias", nil)
|
||||
db.On("Exec", ctx, deleteOrgMemberDBQ, "userID", "orgName", "userAlias").Return(nil)
|
||||
|
|
@ -449,6 +471,7 @@ func TestDeleteMember(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserAliasDBQ, "userID").Return("requestingUserAlias", nil)
|
||||
db.On("Exec", ctx, deleteOrgMemberDBQ, "userID", "orgName", "userAlias").Return(tc.dbErr)
|
||||
|
|
@ -473,6 +496,7 @@ func TestGetAuthorizationPolicyJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetAuthorizationPolicyJSON(context.Background(), "org1")
|
||||
|
|
@ -480,12 +504,14 @@ func TestGetAuthorizationPolicyJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
_, err := m.GetAuthorizationPolicyJSON(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
az := &authz.AuthorizerMock{}
|
||||
az.On("Authorize", ctx, &hub.AuthorizeInput{
|
||||
OrganizationName: "org1",
|
||||
|
|
@ -501,6 +527,7 @@ func TestGetAuthorizationPolicyJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAuthzPolicyDBQ, "userID", "org1").Return([]byte("dataJSON"), nil)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -535,6 +562,7 @@ func TestGetAuthorizationPolicyJSON(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAuthzPolicyDBQ, "userID", "org1").Return(nil, tc.dbErr)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -559,6 +587,7 @@ func TestGetByUserJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetByUserJSON(context.Background())
|
||||
|
|
@ -566,6 +595,7 @@ func TestGetByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserOrgsDBQ, "userID").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -577,6 +607,7 @@ func TestGetByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserOrgsDBQ, "userID").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -592,12 +623,14 @@ func TestGetJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
_, err := m.GetJSON(context.Background(), "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgDBQ, "orgName").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -609,6 +642,7 @@ func TestGetJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgDBQ, "orgName").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -624,6 +658,7 @@ func TestGetMembersJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetMembersJSON(context.Background(), "orgName")
|
||||
|
|
@ -631,12 +666,14 @@ func TestGetMembersJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
_, err := m.GetMembersJSON(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgMembersDBQ, "userID", "orgName").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -664,6 +701,7 @@ func TestGetMembersJSON(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgMembersDBQ, "userID", "orgName").Return(nil, tc.dbErr)
|
||||
m := NewManager(db, nil, nil)
|
||||
|
|
@ -681,6 +719,7 @@ func TestUpdate(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Update(context.Background(), &hub.Organization{})
|
||||
|
|
@ -703,6 +742,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
err := m.Update(ctx, tc.org)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -712,6 +752,7 @@ func TestUpdate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
az := &authz.AuthorizerMock{}
|
||||
az.On("Authorize", ctx, &hub.AuthorizeInput{
|
||||
OrganizationName: "orgName",
|
||||
|
|
@ -726,6 +767,7 @@ func TestUpdate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateOrgDBQ, "userID", mock.Anything).Return(nil)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -759,6 +801,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateOrgDBQ, "userID", mock.Anything).Return(tc.dbErr)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -787,6 +830,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.UpdateAuthorizationPolicy(context.Background(), "org1", &hub.AuthorizationPolicy{})
|
||||
|
|
@ -888,6 +932,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
az := &authz.AuthorizerMock{}
|
||||
az.On("WillUserBeLockedOut", ctx, tc.policy, "userID").Return(true, nil).Maybe()
|
||||
m := NewManager(nil, nil, az)
|
||||
|
|
@ -899,6 +944,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
az := &authz.AuthorizerMock{}
|
||||
az.On("WillUserBeLockedOut", ctx, validPolicy, "userID").Return(false, nil).Maybe()
|
||||
az.On("Authorize", ctx, &hub.AuthorizeInput{
|
||||
|
|
@ -914,6 +960,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateAuthzPolicyDBQ, "userID", "org1", mock.Anything).Return(nil)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -948,6 +995,7 @@ func TestUpdateAuthorizationPolicy(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateAuthzPolicyDBQ, "userID", "org1", mock.Anything).Return(tc.dbErr)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ func TestGet(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
_, err := m.Get(ctx, &hub.GetPackageInput{})
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgDBQ, mock.Anything, mock.Anything).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -34,6 +36,7 @@ func TestGet(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedPackage := &hub.Package{
|
||||
PackageID: "00000000-0000-0000-0000-000000000001",
|
||||
Name: "Package 1",
|
||||
|
|
@ -233,6 +236,7 @@ func TestGetChangeLogJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgChangeLogDBQ, "pkg1").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -244,6 +248,7 @@ func TestGetChangeLogJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgChangeLogDBQ, "pkg1").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -259,12 +264,14 @@ func TestGetJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
_, err := m.GetJSON(ctx, &hub.GetPackageInput{})
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgDBQ, mock.Anything, mock.Anything).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -276,6 +283,7 @@ func TestGetJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgDBQ, mock.Anything, mock.Anything).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -291,6 +299,7 @@ func TestGetRandomJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRandomPkgsDBQ).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -302,6 +311,7 @@ func TestGetRandomJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRandomPkgsDBQ).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -317,6 +327,7 @@ func TestGetSnapshotSecurityReportJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSnapshotSecurityReportDBQ, "pkg1", "1.0.0").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -328,6 +339,7 @@ func TestGetSnapshotSecurityReportJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSnapshotSecurityReportDBQ, "pkg1", "1.0.0").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -343,6 +355,7 @@ func TestGetSnapshotsToScan(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSnapshotsToScanDBQ).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -354,6 +367,7 @@ func TestGetSnapshotsToScan(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSnapshotsToScanDBQ).Return([]byte(`
|
||||
[
|
||||
|
|
@ -387,6 +401,7 @@ func TestGetStarredByUserJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetStarredByUserJSON(context.Background())
|
||||
|
|
@ -394,6 +409,7 @@ func TestGetStarredByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgsStarredByUserDBQ, "userID").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -405,6 +421,7 @@ func TestGetStarredByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgsStarredByUserDBQ, "userID").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -421,6 +438,7 @@ func TestGetStarsJSON(t *testing.T) {
|
|||
pkgID := "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := []struct {
|
||||
errMsg string
|
||||
packageID string
|
||||
|
|
@ -440,6 +458,7 @@ func TestGetStarsJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgStarsDBQ, mock.Anything, pkgID).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -450,6 +469,7 @@ func TestGetStarsJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgStarsDBQ, mock.Anything, pkgID).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -465,6 +485,7 @@ func TestGetStatsJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("packages stats data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgsStatsDBQ).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -476,6 +497,7 @@ func TestGetStatsJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgsStatsDBQ).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -491,6 +513,7 @@ func TestGetValuesSchemaJSON(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getValuesSchemaDBQ, "pkg1", "1.0.0").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -502,6 +525,7 @@ func TestGetValuesSchemaJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getValuesSchemaDBQ, "pkg1", "1.0.0").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -516,7 +540,8 @@ func TestGetValuesSchemaJSON(t *testing.T) {
|
|||
func TestRegister(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
p := &hub.Package{
|
||||
newTestPkg := func() *hub.Package {
|
||||
return &hub.Package{
|
||||
Name: "package1",
|
||||
Description: "description",
|
||||
HomeURL: "home_url",
|
||||
|
|
@ -549,6 +574,7 @@ func TestRegister(t *testing.T) {
|
|||
RepositoryID: "00000000-0000-0000-0000-000000000001",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
|
|
@ -674,6 +700,7 @@ func TestRegister(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.Register(ctx, tc.p)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -683,21 +710,23 @@ func TestRegister(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("successful package registration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, registerPkgDBQ, mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
||||
err := m.Register(ctx, p)
|
||||
err := m.Register(ctx, newTestPkg())
|
||||
assert.NoError(t, err)
|
||||
db.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, registerPkgDBQ, mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
||||
err := m.Register(ctx, p)
|
||||
err := m.Register(ctx, newTestPkg())
|
||||
assert.Equal(t, tests.ErrFakeDB, err)
|
||||
db.AssertExpectations(t)
|
||||
})
|
||||
|
|
@ -765,6 +794,7 @@ func TestSearchJSON(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
dataJSON, err := m.SearchJSON(ctx, tc.input)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -775,6 +805,7 @@ func TestSearchJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, searchPkgsDBQ, mock.Anything).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -786,6 +817,7 @@ func TestSearchJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, searchPkgsDBQ, mock.Anything).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -803,6 +835,7 @@ func TestSearchMonocularJSON(t *testing.T) {
|
|||
searchTerm := "text"
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, searchPkgsMonocularDBQ, baseURL, searchTerm).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -814,6 +847,7 @@ func TestSearchMonocularJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, searchPkgsMonocularDBQ, baseURL, searchTerm).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -830,6 +864,7 @@ func TestToggleStar(t *testing.T) {
|
|||
pkgID := "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.ToggleStar(context.Background(), "pkgID")
|
||||
|
|
@ -847,6 +882,7 @@ func TestToggleStar(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.ToggleStar(ctx, tc.packageID)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -856,6 +892,7 @@ func TestToggleStar(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, togglePkgStarDBQ, "userID", pkgID).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -866,6 +903,7 @@ func TestToggleStar(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, togglePkgStarDBQ, "userID", pkgID).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -897,6 +935,7 @@ func TestUpdateSnapshotSecurityReport(t *testing.T) {
|
|||
sJSON, _ := json.Marshal(s)
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateSnapshotSecurityReportDBQ, sJSON).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -907,6 +946,7 @@ func TestUpdateSnapshotSecurityReport(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database update succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateSnapshotSecurityReportDBQ, sJSON).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -954,6 +994,7 @@ func TestUnregister(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.Unregister(ctx, tc.p)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -963,6 +1004,7 @@ func TestUnregister(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("successful package unregistration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, unregisterPkgDBQ, mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -973,6 +1015,7 @@ func TestUnregister(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, unregisterPkgDBQ, mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ func TestPreparePackageFromMetadata(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
pkg, err := PreparePackageFromMetadata(tc.md)
|
||||
if tc.expectedErr == nil {
|
||||
assert.Nil(t, err)
|
||||
|
|
@ -182,6 +183,7 @@ func TestValidatePackageMetadata(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := ValidatePackageMetadata(tc.md)
|
||||
assert.True(t, errors.Is(err, ErrInvalidMetadata))
|
||||
assert.Contains(t, err.Error(), tc.errMsg)
|
||||
|
|
@ -190,6 +192,7 @@ func TestValidatePackageMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("valid metadata", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
md := &hub.PackageMetadata{
|
||||
Version: "1.0.0",
|
||||
Name: "pkg1",
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ func TestAdd(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Add(context.Background(), "orgName", nil)
|
||||
|
|
@ -174,6 +175,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
l := &HelmIndexLoaderMock{}
|
||||
if tc.lErr != nil {
|
||||
l.On("LoadIndex", tc.r).Return(nil, "", tc.lErr)
|
||||
|
|
@ -191,6 +193,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
r := &hub.Repository{
|
||||
Name: "repo1",
|
||||
DisplayName: "Repository 1",
|
||||
|
|
@ -242,6 +245,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addRepoDBQ, "userID", "orgName", mock.Anything).Return(tc.dbErr)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -287,6 +291,7 @@ func TestAdd(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addRepoDBQ, "userID", "orgName", mock.Anything).Return(nil)
|
||||
az := &authz.AuthorizerMock{}
|
||||
|
|
@ -334,6 +339,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.CheckAvailability(context.Background(), tc.resourceKind, tc.value)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -362,6 +368,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("resource kind: %s", tc.resourceKind), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tc.dbQuery = fmt.Sprintf("select not exists (%s)", tc.dbQuery)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, tc.dbQuery, "value").Return(tc.available, nil)
|
||||
|
|
@ -376,6 +383,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
dbQuery := fmt.Sprintf(`select not exists (%s)`, checkRepoNameAvailDBQ)
|
||||
db.On("QueryRow", ctx, dbQuery, "value").Return(false, tests.ErrFakeDB)
|
||||
|
|
@ -399,6 +407,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.ClaimOwnership(context.Background(), "repo1", "")
|
||||
|
|
@ -418,6 +427,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
|
||||
err := m.ClaimOwnership(ctx, tc.repoName, "")
|
||||
|
|
@ -427,6 +437,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim failed: database error getting repository", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -437,6 +448,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim failed: error getting repository metadata", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(helmRepoJSON, nil)
|
||||
hg := &tests.HTTPGetterMock{}
|
||||
|
|
@ -456,6 +468,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim failed: oci repo", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(ociRepoJSON, nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -466,6 +479,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim failed: database error getting user email", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(helmRepoJSON, nil)
|
||||
db.On("QueryRow", ctx, getUserEmailDBQ, userID).Return("", tests.ErrFakeDB)
|
||||
|
|
@ -483,6 +497,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim failed: user not in repository owners list", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(helmRepoJSON, nil)
|
||||
db.On("QueryRow", ctx, getUserEmailDBQ, userID).Return("user1@email.com", nil)
|
||||
|
|
@ -500,6 +515,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim succeeded (helm)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(helmRepoJSON, nil)
|
||||
db.On("QueryRow", ctx, getUserEmailDBQ, userID).Return("owner1@email.com", nil)
|
||||
|
|
@ -518,6 +534,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim failed (opa): error cloning repository", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(opaRepoJSON, nil)
|
||||
rc := &ClonerMock{}
|
||||
|
|
@ -532,6 +549,7 @@ func TestClaimOwnership(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("ownership claim succeeded (opa)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(opaRepoJSON, nil)
|
||||
db.On("QueryRow", ctx, getUserEmailDBQ, userID).Return("owner1@email.com", nil)
|
||||
|
|
@ -552,6 +570,7 @@ func TestDelete(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Delete(context.Background(), "repo1")
|
||||
|
|
@ -559,12 +578,14 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
err := m.Delete(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -603,6 +624,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -629,6 +651,7 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("delete repository succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -647,6 +670,7 @@ func TestDelete(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
db := &tests.DBMock{}
|
||||
|
|
@ -710,6 +734,7 @@ func TestGetAllJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAllReposDBQ, false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -721,6 +746,7 @@ func TestGetAllJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("all repositories data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAllReposDBQ, false).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -753,6 +779,7 @@ func TestGetByID(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errStr, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
|
||||
_, err := m.GetByID(ctx, tc.repoID, false)
|
||||
|
|
@ -763,6 +790,7 @@ func TestGetByID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByIDDBQ, repoID, false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -774,6 +802,7 @@ func TestGetByID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByIDDBQ, repoID, false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -802,6 +831,7 @@ func TestGetByID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetByKind(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
|
||||
db := &tests.DBMock{}
|
||||
|
|
@ -850,6 +880,7 @@ func TestGetByKindJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getReposByKindDBQ, hub.OLM, false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -861,6 +892,7 @@ func TestGetByKindJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("all repositories data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getReposByKindDBQ, hub.OLM, false).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -876,12 +908,14 @@ func TestGetByName(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetByName(ctx, "", false)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("get existing repository by name", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -911,6 +945,7 @@ func TestGetByName(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -922,6 +957,7 @@ func TestGetByName(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid json data returned from database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte("invalid json"), nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -935,6 +971,7 @@ func TestGetByName(t *testing.T) {
|
|||
|
||||
func TestGetMetadata(t *testing.T) {
|
||||
t.Run("local file: error reading repository metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetMetadata("testdata/not-exists.yaml")
|
||||
assert.Error(t, err)
|
||||
|
|
@ -942,6 +979,7 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("remote file: error downloading repository metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hg := &tests.HTTPGetterMock{}
|
||||
hg.On("Get", "http://url.test/not-found.yml").Return(nil, tests.ErrFake)
|
||||
hg.On("Get", "http://url.test/not-found.yaml").Return(nil, tests.ErrFake)
|
||||
|
|
@ -952,6 +990,7 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("remote file: unexpected status code received", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hg := &tests.HTTPGetterMock{}
|
||||
hg.On("Get", "http://url.test/not-found.yml").Return(&http.Response{
|
||||
Body: ioutil.NopCloser(strings.NewReader("")),
|
||||
|
|
@ -968,6 +1007,7 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("remote file: error reading repository metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hg := &tests.HTTPGetterMock{}
|
||||
hg.On("Get", "http://url.test/not-found.yml").Return(&http.Response{
|
||||
Body: ioutil.NopCloser(tests.ErrReader(0)),
|
||||
|
|
@ -984,6 +1024,7 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error unmarshaling repository metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetMetadata("testdata/invalid")
|
||||
assert.Error(t, err)
|
||||
|
|
@ -991,6 +1032,7 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid repository id", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetMetadata("testdata/invalid-repo-id")
|
||||
assert.Error(t, err)
|
||||
|
|
@ -998,18 +1040,21 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("local file: success fetching .yml", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetMetadata("testdata/artifacthub-repo")
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("local file: success .yaml", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetMetadata("testdata/test-yaml-repo")
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("remote file: success", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hg := &tests.HTTPGetterMock{}
|
||||
hg.On("Get", "http://url.test/ok.yml").Return(&http.Response{
|
||||
Body: ioutil.NopCloser(strings.NewReader("repositoryID: 00000000-0000-0000-0000-000000000001")),
|
||||
|
|
@ -1021,6 +1066,7 @@ func TestGetMetadata(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("remote file: success on yaml", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hg := &tests.HTTPGetterMock{}
|
||||
hg.On("Get", "http://url.test/ok.yaml").Return(&http.Response{
|
||||
Body: ioutil.NopCloser(strings.NewReader("repositoryID: 00000000-0000-0000-0000-000000000001")),
|
||||
|
|
@ -1040,12 +1086,14 @@ func TestGetPackagesDigest(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetPackagesDigest(context.Background(), "invalid")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoPkgsDigestDBQ, "00000000-0000-0000-0000-000000000001").Return([]byte(`
|
||||
{
|
||||
|
|
@ -1072,6 +1120,7 @@ func TestGetOwnedByOrgJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetOwnedByOrgJSON(context.Background(), "orgName", false)
|
||||
|
|
@ -1079,12 +1128,14 @@ func TestGetOwnedByOrgJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
_, err := m.GetOwnedByOrgJSON(ctx, "", false)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgReposDBQ, "userID", "orgName", false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1096,6 +1147,7 @@ func TestGetOwnedByOrgJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("org repositories data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgReposDBQ, "userID", "orgName", false).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1111,6 +1163,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetOwnedByUserJSON(context.Background(), false)
|
||||
|
|
@ -1118,6 +1171,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserReposDBQ, "userID", false).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1129,6 +1183,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("user repositories data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserReposDBQ, "userID", false).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1149,6 +1204,7 @@ func TestGetRemoteDigest(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("helm-http: error loading index", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
l := &HelmIndexLoaderMock{}
|
||||
l.On("LoadIndex", helmHTTP).Return(nil, "", tests.ErrFake)
|
||||
m := NewManager(cfg, nil, nil, WithHelmIndexLoader(l))
|
||||
|
|
@ -1159,6 +1215,7 @@ func TestGetRemoteDigest(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("helm-http: error reading index file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
l := &HelmIndexLoaderMock{}
|
||||
l.On("LoadIndex", helmHTTP).Return(nil, "invalid-path", nil)
|
||||
m := NewManager(cfg, nil, nil, WithHelmIndexLoader(l))
|
||||
|
|
@ -1169,6 +1226,7 @@ func TestGetRemoteDigest(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("helm-http: success", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
f, err := ioutil.TempFile("", "")
|
||||
require.NoError(t, err)
|
||||
_, _ = f.Write([]byte("indexFileContent"))
|
||||
|
|
@ -1189,12 +1247,14 @@ func TestSetLastTrackingResults(t *testing.T) {
|
|||
repoID := "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
err := m.SetLastTrackingResults(ctx, "invalid", "errors")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database update succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, setLastTrackingResultsDBQ, repoID, "errors", false).Return(nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1205,6 +1265,7 @@ func TestSetLastTrackingResults(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, setLastTrackingResultsDBQ, repoID, "errors", false).Return(tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1220,12 +1281,14 @@ func TestSetVerifiedPublisher(t *testing.T) {
|
|||
repoID := "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
err := m.SetVerifiedPublisher(ctx, "invalid", true)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database update succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, setVerifiedPublisherDBQ, repoID, true).Return(nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1236,6 +1299,7 @@ func TestSetVerifiedPublisher(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, setVerifiedPublisherDBQ, repoID, true).Return(tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1254,6 +1318,7 @@ func TestTransfer(t *testing.T) {
|
|||
orgP := &org
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Transfer(context.Background(), "repo1", "", false)
|
||||
|
|
@ -1273,6 +1338,7 @@ func TestTransfer(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
|
||||
err := m.Transfer(ctx, tc.repoName, "", false)
|
||||
|
|
@ -1282,6 +1348,7 @@ func TestTransfer(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -1320,6 +1387,7 @@ func TestTransfer(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -1346,6 +1414,7 @@ func TestTransfer(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("transfer repository succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -1367,6 +1436,7 @@ func TestUpdate(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(cfg, nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Update(context.Background(), nil)
|
||||
|
|
@ -1454,6 +1524,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
l := &HelmIndexLoaderMock{}
|
||||
if tc.lErr != nil {
|
||||
l.On("LoadIndex", tc.r).Return(nil, "", tc.lErr)
|
||||
|
|
@ -1470,6 +1541,7 @@ func TestUpdate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("authorization failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
r := &hub.Repository{
|
||||
Name: "repo1",
|
||||
DisplayName: "Repository 1",
|
||||
|
|
@ -1530,6 +1602,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, "repo1", false).Return([]byte(`
|
||||
{
|
||||
|
|
@ -1583,6 +1656,7 @@ func TestUpdate(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
repoJSON, _ := json.Marshal(tc.r)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getRepoByNameDBQ, tc.r.Name, false).Return(repoJSON, nil)
|
||||
|
|
@ -1608,6 +1682,7 @@ func TestUpdateDigest(t *testing.T) {
|
|||
digest := "digest"
|
||||
|
||||
t.Run("database update succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateRepoDigestDBQ, repositoryID, digest).Return(nil)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
@ -1618,6 +1693,7 @@ func TestUpdateDigest(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateRepoDigestDBQ, repositoryID, digest).Return(tests.ErrFakeDB)
|
||||
m := NewManager(cfg, db, nil)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ func TestScanSnapshot(t *testing.T) {
|
|||
image := "repo/image:tag"
|
||||
|
||||
t.Run("error scanning image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
scannerMock := &Mock{}
|
||||
scannerMock.On("Scan", image).Return(nil, tests.ErrFake)
|
||||
|
||||
|
|
@ -37,6 +38,7 @@ func TestScanSnapshot(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("image using latest tag", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
scannerMock := &Mock{}
|
||||
|
||||
snapshot := &hub.SnapshotToScan{
|
||||
|
|
@ -59,6 +61,7 @@ func TestScanSnapshot(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("image not found", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
scannerMock := &Mock{}
|
||||
scannerMock.On("Scan", image).Return(nil, ErrImageNotFound)
|
||||
|
||||
|
|
@ -82,6 +85,7 @@ func TestScanSnapshot(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error unmarshalling report", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
scannerMock := &Mock{}
|
||||
scannerMock.On("Scan", image).Return(`invalid: "`, nil)
|
||||
|
||||
|
|
@ -100,6 +104,7 @@ func TestScanSnapshot(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("image report generated successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
scannerMock := &Mock{}
|
||||
scannerMock.On("Scan", image).Return(sampleReportData, nil)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ func TestAdd(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Add(context.Background(), &hub.Subscription{})
|
||||
|
|
@ -50,6 +51,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.Add(ctx, tc.s)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -58,26 +60,31 @@ func TestAdd(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
s := &hub.Subscription{
|
||||
PackageID: packageID,
|
||||
EventKind: hub.NewRelease,
|
||||
}
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addSubscriptionDBQ, mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
||||
s := &hub.Subscription{
|
||||
PackageID: packageID,
|
||||
EventKind: hub.NewRelease,
|
||||
}
|
||||
err := m.Add(ctx, s)
|
||||
assert.Equal(t, tests.ErrFakeDB, err)
|
||||
db.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addSubscriptionDBQ, mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
||||
s := &hub.Subscription{
|
||||
PackageID: packageID,
|
||||
EventKind: hub.NewRelease,
|
||||
}
|
||||
err := m.Add(ctx, s)
|
||||
assert.NoError(t, err)
|
||||
db.AssertExpectations(t)
|
||||
|
|
@ -88,6 +95,7 @@ func TestAddOptOut(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.AddOptOut(context.Background(), &hub.OptOut{})
|
||||
|
|
@ -117,6 +125,7 @@ func TestAddOptOut(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.AddOptOut(ctx, tc.o)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -125,26 +134,31 @@ func TestAddOptOut(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
o := &hub.OptOut{
|
||||
RepositoryID: repositoryID,
|
||||
EventKind: hub.RepositoryTrackingErrors,
|
||||
}
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addOptOutDBQ, mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
||||
o := &hub.OptOut{
|
||||
RepositoryID: repositoryID,
|
||||
EventKind: hub.RepositoryTrackingErrors,
|
||||
}
|
||||
err := m.AddOptOut(ctx, o)
|
||||
assert.Equal(t, tests.ErrFakeDB, err)
|
||||
db.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addOptOutDBQ, mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
||||
o := &hub.OptOut{
|
||||
RepositoryID: repositoryID,
|
||||
EventKind: hub.RepositoryTrackingErrors,
|
||||
}
|
||||
err := m.AddOptOut(ctx, o)
|
||||
assert.NoError(t, err)
|
||||
db.AssertExpectations(t)
|
||||
|
|
@ -155,6 +169,7 @@ func TestDelete(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Delete(context.Background(), &hub.Subscription{})
|
||||
|
|
@ -183,6 +198,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.Delete(ctx, tc.s)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -191,26 +207,31 @@ func TestDelete(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
s := &hub.Subscription{
|
||||
PackageID: packageID,
|
||||
EventKind: hub.NewRelease,
|
||||
}
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteSubscriptionDBQ, mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
||||
s := &hub.Subscription{
|
||||
PackageID: packageID,
|
||||
EventKind: hub.NewRelease,
|
||||
}
|
||||
err := m.Delete(ctx, s)
|
||||
assert.Equal(t, tests.ErrFakeDB, err)
|
||||
db.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteSubscriptionDBQ, mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
||||
s := &hub.Subscription{
|
||||
PackageID: packageID,
|
||||
EventKind: hub.NewRelease,
|
||||
}
|
||||
err := m.Delete(ctx, s)
|
||||
assert.NoError(t, err)
|
||||
db.AssertExpectations(t)
|
||||
|
|
@ -221,6 +242,7 @@ func TestDeleteOptOut(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.DeleteOptOut(context.Background(), optOutID)
|
||||
|
|
@ -240,6 +262,7 @@ func TestDeleteOptOut(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.DeleteOptOut(ctx, tc.optOutID)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -249,6 +272,7 @@ func TestDeleteOptOut(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteOptOutDBQ, userID, optOutID).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -259,6 +283,7 @@ func TestDeleteOptOut(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteOptOutDBQ, userID, optOutID).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -273,6 +298,7 @@ func TestGetByPackageJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetByPackageJSON(context.Background(), "")
|
||||
|
|
@ -280,6 +306,7 @@ func TestGetByPackageJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
_, err := m.GetByPackageJSON(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -287,6 +314,7 @@ func TestGetByPackageJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserPkgSubscriptionsDBQ, userID, packageID).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -298,6 +326,7 @@ func TestGetByPackageJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserPkgSubscriptionsDBQ, userID, packageID).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -313,6 +342,7 @@ func TestGetByUserJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetByUserJSON(context.Background())
|
||||
|
|
@ -320,6 +350,7 @@ func TestGetByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserSubscriptionsDBQ, userID).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -331,6 +362,7 @@ func TestGetByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserSubscriptionsDBQ, userID).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -346,6 +378,7 @@ func TestGetOptOutListJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, userID)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetOptOutListJSON(context.Background())
|
||||
|
|
@ -353,6 +386,7 @@ func TestGetOptOutListJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserOptOutEntriesDBQ, userID).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -364,6 +398,7 @@ func TestGetOptOutListJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserOptOutEntriesDBQ, userID).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -397,6 +432,7 @@ func TestGetSubscriptors(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getPkgSubscriptorsDBQ, packageID, hub.EventKind(0)).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -408,6 +444,7 @@ func TestGetSubscriptors(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded (pkg new release event)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedSubscriptors := []*hub.User{
|
||||
{
|
||||
UserID: "00000000-0000-0000-0000-000000000001",
|
||||
|
|
@ -438,6 +475,7 @@ func TestGetSubscriptors(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded (repo tracking errors event)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedSubscriptors := []*hub.User{
|
||||
{
|
||||
UserID: "00000000-0000-0000-0000-000000000001",
|
||||
|
|
@ -457,6 +495,7 @@ func TestGetSubscriptors(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded (repo ownership claim event)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedSubscriptors := []*hub.User{
|
||||
{
|
||||
UserID: "00000000-0000-0000-0000-000000000001",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func TestDBErrorsCollector(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup errors collector
|
||||
rm := &repo.ManagerMock{}
|
||||
repos := []*hub.Repository{
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ func TestTracker(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("error cloning repository", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return("", "", tests.ErrFake)
|
||||
|
|
@ -43,6 +45,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error loading repository registered packages", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return("", "", nil)
|
||||
|
|
@ -55,6 +59,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no packages in path, nothing to do", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path1", nil)
|
||||
|
|
@ -68,6 +74,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid package metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path2", nil)
|
||||
|
|
@ -82,6 +90,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid version in package metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path3", nil)
|
||||
|
|
@ -96,6 +106,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error registering package version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -112,6 +124,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no need to register package version because it is already registered", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -128,6 +142,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version registered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -164,6 +180,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error unregistering package version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path5", nil)
|
||||
|
|
@ -186,6 +204,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no packages unregistered because there are no packages available", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path1", nil)
|
||||
|
|
@ -202,6 +222,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version unregistered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path5", nil)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ func TestMain(m *testing.M) {
|
|||
|
||||
func TestTracker(t *testing.T) {
|
||||
t.Run("error loading registered packages digest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
r := &hub.Repository{RepositoryID: "repo1"}
|
||||
tw := newTrackerWrapper(r)
|
||||
|
|
@ -38,6 +40,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error loading repository index file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: "repo1",
|
||||
|
|
@ -54,6 +58,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error loading repository tags", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: "repo1",
|
||||
|
|
@ -310,6 +316,8 @@ func TestTracker(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("Test case %d", tc.n), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(tc.r)
|
||||
tw.rm.On("GetPackagesDigest", tw.ctx, tc.r.RepositoryID).
|
||||
|
|
@ -450,6 +458,8 @@ func TestTracker(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("Test case %d", tc.n), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(tc.r)
|
||||
tw.rm.On("GetPackagesDigest", tw.ctx, tc.r.RepositoryID).
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ func TestWorker(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("error downloading chart", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -66,6 +68,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error downloading chart (deprecated chart)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
job := &Job{
|
||||
|
|
@ -93,6 +97,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("unexpected status downloading chart", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -110,6 +116,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error downloading logo image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -136,6 +144,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("unexpected status downloading logo image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -165,6 +175,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error saving logo image", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -195,6 +207,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error registering package", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -225,6 +239,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package registered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -324,6 +340,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package with logo in data url registered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
job := &Job{
|
||||
|
|
@ -366,6 +384,8 @@ func TestWorker(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("error unregistering package", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -379,6 +399,8 @@ func TestWorker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package unregistered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup worker and expectations
|
||||
ww := newWorkerWrapper(context.Background())
|
||||
ww.queue <- job
|
||||
|
|
@ -713,6 +735,7 @@ func TestEnrichPackageFromAnnotations(t *testing.T) {
|
|||
for i, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := enrichPackageFromAnnotations(tc.pkg, tc.annotations)
|
||||
if tc.expectedErrMsg != "" {
|
||||
assert.Error(t, err)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ func TestTracker(t *testing.T) {
|
|||
imageData, _ := ioutil.ReadFile("testdata/red-dot.png")
|
||||
|
||||
t.Run("error exporting repository packages", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r2)
|
||||
tw.re.On("ExportRepository", tw.ctx, r2).Return("", tests.ErrFake)
|
||||
|
|
@ -50,6 +52,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error cloning repository", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return("", "", tests.ErrFake)
|
||||
|
|
@ -61,6 +65,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error loading repository registered packages", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return("", "", nil)
|
||||
|
|
@ -73,6 +79,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no packages in path, nothing to do", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path1", nil)
|
||||
|
|
@ -86,6 +94,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package does not have a manifest file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path2", nil)
|
||||
|
|
@ -99,6 +109,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting package version csv", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path3", nil)
|
||||
|
|
@ -113,6 +125,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error registering package version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -129,6 +143,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no need to register package version because it is already registered", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -144,6 +160,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version registered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -232,6 +250,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error unregistering package version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path5", nil)
|
||||
|
|
@ -255,6 +275,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no packages unregistered because there are no packages available", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path1", nil)
|
||||
|
|
@ -272,6 +294,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version unregistered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r1)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r1).Return(".", "testdata/path5", nil)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ func TestTracker(t *testing.T) {
|
|||
imageData, _ := ioutil.ReadFile("testdata/path4/red-dot.png")
|
||||
|
||||
t.Run("error cloning repository", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return("", "", tests.ErrFake)
|
||||
|
|
@ -44,6 +46,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error loading repository registered packages", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return("", "", nil)
|
||||
|
|
@ -56,6 +60,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no packages in path, nothing to do", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path1", nil)
|
||||
|
|
@ -69,6 +75,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid package metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path2", nil)
|
||||
|
|
@ -83,6 +91,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid version in package metadata file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path3", nil)
|
||||
|
|
@ -97,6 +107,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error registering package version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -114,6 +126,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no need to register package version because it is already registered", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -130,6 +144,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version registered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path4", nil)
|
||||
|
|
@ -190,6 +206,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version not registered as there are no policies files available", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path5", nil)
|
||||
|
|
@ -204,6 +222,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error unregistering package version", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path6", nil)
|
||||
|
|
@ -226,6 +246,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("no packages unregistered because there are no packages available", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path1", nil)
|
||||
|
|
@ -242,6 +264,8 @@ func TestTracker(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("package version unregistered successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup tracker and expectations
|
||||
tw := newTrackerWrapper(r)
|
||||
tw.rc.On("CloneRepository", tw.ctx, r).Return(".", "testdata/path6", nil)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("error getting repository by name", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetByName", ctx, "repo1", true).Return(nil, tests.ErrFake)
|
||||
|
|
@ -43,6 +45,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get repositories by name", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetByName", ctx, "repo1", true).Return(repo1, nil)
|
||||
|
|
@ -58,6 +62,7 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting kind from name", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := viper.New()
|
||||
cfg.Set("tracker.repositoriesKinds", []string{"invalid"})
|
||||
repos, err := GetRepositories(ctx, cfg, nil)
|
||||
|
|
@ -66,6 +71,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting repository by kind", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetByKind", ctx, hub.Helm, true).Return(nil, tests.ErrFake)
|
||||
|
|
@ -80,6 +87,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get repositories by kind", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetByKind", ctx, hub.Helm, true).Return([]*hub.Repository{repo1}, nil)
|
||||
|
|
@ -95,6 +104,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("names have preference over kinds when both are provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetByName", ctx, "repo1", true).Return(repo1, nil)
|
||||
|
|
@ -111,6 +122,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting all repositories", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetAll", ctx, true).Return(nil, tests.ErrFake)
|
||||
|
|
@ -124,6 +137,8 @@ func TestGetRepositories(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("get all repositories", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
rm := &repo.ManagerMock{}
|
||||
rm.On("GetAll", ctx, true).Return([]*hub.Repository{repo1, repo2, repo3}, nil)
|
||||
|
|
@ -141,6 +156,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("error getting repository remote digest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{}
|
||||
rm := &repo.ManagerMock{}
|
||||
|
|
@ -154,6 +171,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("repository has't been updated, same digest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
Digest: "digest",
|
||||
|
|
@ -169,6 +188,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("repository hasn't been updated, but bypassDigestCheck is enabled", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
Digest: "digest",
|
||||
|
|
@ -187,6 +208,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error tracking repository", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{}
|
||||
rm := &repo.ManagerMock{}
|
||||
|
|
@ -201,6 +224,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("repository tracked successfully, no need to update digest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{}
|
||||
rm := &repo.ManagerMock{}
|
||||
|
|
@ -215,6 +240,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("repository tracked successfully, digest updated", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
Digest: "digest1",
|
||||
|
|
@ -232,6 +259,8 @@ func TestTrackRepository(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error updating repository digest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
Digest: "digest1",
|
||||
|
|
@ -256,6 +285,8 @@ func TestSetVerifiedPublisherFlag(t *testing.T) {
|
|||
repo1ID := "00000000-0000-0000-0000-000000000001"
|
||||
|
||||
t.Run("verified publisher flag set to true successfully (remote url)", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: repo1ID,
|
||||
|
|
@ -272,6 +303,8 @@ func TestSetVerifiedPublisherFlag(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("verified publisher flag not set as it was already true", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: repo1ID,
|
||||
|
|
@ -287,6 +320,8 @@ func TestSetVerifiedPublisherFlag(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("verified publisher flag not set: it was false and md file did not exist", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: repo1ID,
|
||||
|
|
@ -302,6 +337,8 @@ func TestSetVerifiedPublisherFlag(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("verified publisher flag set to false: it was true and md file did not exist", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: repo1ID,
|
||||
|
|
@ -318,6 +355,8 @@ func TestSetVerifiedPublisherFlag(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("set verified publisher flag failed", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup expectations
|
||||
r := &hub.Repository{
|
||||
RepositoryID: repo1ID,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ func TestCheckAPIKey(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
_, err := m.CheckAPIKey(ctx, tc.key)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -45,6 +46,7 @@ func TestCheckAPIKey(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("key not found in database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAPIKeyUserIDDBQ, []byte("key")).Return(nil, pgx.ErrNoRows)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -57,6 +59,7 @@ func TestCheckAPIKey(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting key from database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAPIKeyUserIDDBQ, []byte("key")).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -68,6 +71,7 @@ func TestCheckAPIKey(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("valid key", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getAPIKeyUserIDDBQ, []byte("key")).Return("userID", nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -103,6 +107,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
_, err := m.CheckAvailability(ctx, tc.resourceKind, tc.value)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -126,6 +131,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(fmt.Sprintf("resource kind: %s", tc.resourceKind), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tc.dbQuery = fmt.Sprintf("select not exists (%s)", tc.dbQuery)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, tc.dbQuery, "value").Return(tc.available, nil)
|
||||
|
|
@ -140,6 +146,7 @@ func TestCheckAvailability(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
dbQuery := fmt.Sprintf(`select not exists (%s)`, checkUserAliasAvailDBQ)
|
||||
db.On("QueryRow", ctx, dbQuery, "value").Return(false, tests.ErrFakeDB)
|
||||
|
|
@ -175,6 +182,7 @@ func TestCheckCredentials(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
_, err := m.CheckCredentials(ctx, tc.email, tc.password)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -184,6 +192,7 @@ func TestCheckCredentials(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("credentials provided not found in database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, checkUserCredsDBQ, "email").Return(nil, pgx.ErrNoRows)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -196,6 +205,7 @@ func TestCheckCredentials(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting credentials from database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, checkUserCredsDBQ, "email").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -207,6 +217,7 @@ func TestCheckCredentials(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid credentials provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
pw, _ := bcrypt.GenerateFromPassword([]byte("pass"), bcrypt.DefaultCost)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, checkUserCredsDBQ, "email").Return([]interface{}{"userID", string(pw)}, nil)
|
||||
|
|
@ -220,6 +231,7 @@ func TestCheckCredentials(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("valid credentials provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
pw, _ := bcrypt.GenerateFromPassword([]byte("pass"), bcrypt.DefaultCost)
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, checkUserCredsDBQ, "email").Return([]interface{}{"userID", string(pw)}, nil)
|
||||
|
|
@ -261,6 +273,7 @@ func TestCheckSession(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
_, err := m.CheckSession(ctx, tc.sessionID, tc.duration)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -270,6 +283,7 @@ func TestCheckSession(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("session not found in database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSessionDBQ, []byte("sessionID")).Return(nil, pgx.ErrNoRows)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -282,6 +296,7 @@ func TestCheckSession(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("error getting session from database", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSessionDBQ, []byte("sessionID")).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -293,6 +308,7 @@ func TestCheckSession(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("session has expired", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSessionDBQ, []byte("sessionID")).Return([]interface{}{"userID", int64(1)}, nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -305,6 +321,7 @@ func TestCheckSession(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("valid session", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getSessionDBQ, []byte("sessionID")).Return([]interface{}{
|
||||
"userID",
|
||||
|
|
@ -343,6 +360,7 @@ func TestDeleteSession(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
err := m.DeleteSession(ctx, tc.sessionID)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -368,6 +386,7 @@ func TestDeleteSession(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteSessionDBQ, []byte("sessionID")).Return(tc.dbResponse)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -384,6 +403,7 @@ func TestGetProfile(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetProfile(context.Background())
|
||||
|
|
@ -391,6 +411,7 @@ func TestGetProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserProfileDBQ, "userID").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -402,6 +423,7 @@ func TestGetProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedProfile := &hub.User{
|
||||
Alias: "alias",
|
||||
FirstName: "first_name",
|
||||
|
|
@ -433,6 +455,7 @@ func TestGetProfileJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetProfileJSON(context.Background())
|
||||
|
|
@ -440,6 +463,7 @@ func TestGetProfileJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserProfileDBQ, "userID").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -451,6 +475,7 @@ func TestGetProfileJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserProfileDBQ, "userID").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -466,12 +491,14 @@ func TestGetUserID(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
_, err := m.GetUserID(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserIDDBQ, "email").Return("userID", nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -483,6 +510,7 @@ func TestGetUserID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserIDDBQ, "email").Return("", tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -520,6 +548,7 @@ func TestRegisterSession(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
s := &hub.Session{UserID: tc.userID}
|
||||
_, err := m.RegisterSession(ctx, s)
|
||||
|
|
@ -530,6 +559,7 @@ func TestRegisterSession(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("successful session registration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, registerSessionDBQ, mock.Anything).Return([]byte("sessionID"), nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -541,6 +571,7 @@ func TestRegisterSession(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, registerSessionDBQ, mock.Anything).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -585,6 +616,7 @@ func TestRegisterUser(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
es := &email.SenderMock{}
|
||||
es.On("SendEmail", mock.Anything).Return(nil)
|
||||
m := NewManager(nil, es)
|
||||
|
|
@ -614,6 +646,7 @@ func TestRegisterUser(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, registerUserDBQ, mock.Anything).Return(&code, nil)
|
||||
es := &email.SenderMock{}
|
||||
|
|
@ -638,6 +671,7 @@ func TestRegisterUser(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error registering user", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
code := ""
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, registerUserDBQ, mock.Anything).Return(&code, tests.ErrFakeDB)
|
||||
|
|
@ -658,6 +692,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
oldHashed, _ := bcrypt.GenerateFromPassword([]byte("old"), bcrypt.DefaultCost)
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.UpdatePassword(context.Background(), "old", "new")
|
||||
|
|
@ -684,6 +719,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
err := m.UpdatePassword(ctx, tc.old, tc.new)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -693,6 +729,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error getting user password", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserPasswordDBQ, "userID").Return("", tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -703,6 +740,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid user password provided", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserPasswordDBQ, "userID").Return(string(oldHashed), nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -713,6 +751,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error updating password", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserPasswordDBQ, "userID").Return(string(oldHashed), nil)
|
||||
db.On("Exec", ctx, updateUserPasswordDBQ, "userID", mock.Anything, mock.Anything).
|
||||
|
|
@ -725,6 +764,7 @@ func TestUpdatePassword(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("successful password update", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserPasswordDBQ, "userID").Return(string(oldHashed), nil)
|
||||
db.On("Exec", ctx, updateUserPasswordDBQ, "userID", mock.Anything, mock.Anything).Return(nil)
|
||||
|
|
@ -740,6 +780,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.UpdateProfile(context.Background(), &hub.User{})
|
||||
|
|
@ -763,6 +804,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
err := m.UpdateProfile(ctx, tc.user)
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -772,6 +814,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database query succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateUserProfileDBQ, "userID", mock.Anything).Return(nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -782,6 +825,7 @@ func TestUpdateProfile(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateUserProfileDBQ, "userID", mock.Anything).Return(tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -796,12 +840,14 @@ func TestVerifyEmail(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil, nil)
|
||||
_, err := m.VerifyEmail(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("successful email verification", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, verifyEmailDBQ, "emailVerificationCode").Return(true, nil)
|
||||
m := NewManager(db, nil)
|
||||
|
|
@ -813,6 +859,7 @@ func TestVerifyEmail(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error verifying email", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, verifyEmailDBQ, "emailVerificationCode").Return(false, tests.ErrFakeDB)
|
||||
m := NewManager(db, nil)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func TestSetupConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Check config file must exist for test cmd
|
||||
cfg, err := SetupConfig("test")
|
||||
require.Error(t, err)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import (
|
|||
)
|
||||
|
||||
func TestSetupImageStore(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Check a valid image store provider must be provided
|
||||
cfg := viper.New()
|
||||
cfg.Set("tracker.imageStore", "invalid")
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func TestSetupLogger(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Check a valid log level must be provided
|
||||
cfg := viper.New()
|
||||
cfg.Set("log.level", "invalid")
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ func TestAdd(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Add(context.Background(), "orgName", wh)
|
||||
|
|
@ -105,6 +106,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
|
||||
err := m.Add(ctx, tc.orgName, tc.wh)
|
||||
|
|
@ -131,6 +133,7 @@ func TestAdd(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addWebhookDBQ, "userID", "orgName", mock.Anything).Return(tc.dbErr)
|
||||
m := NewManager(db)
|
||||
|
|
@ -143,6 +146,7 @@ func TestAdd(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("add webhook succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, addWebhookDBQ, "userID", "orgName", mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -157,6 +161,7 @@ func TestDelete(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Delete(context.Background(), validUUID)
|
||||
|
|
@ -164,6 +169,7 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
err := m.Delete(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -186,6 +192,7 @@ func TestDelete(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteWebhookDBQ, "userID", validUUID).Return(tc.dbErr)
|
||||
m := NewManager(db)
|
||||
|
|
@ -198,6 +205,7 @@ func TestDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("delete webhook succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, deleteWebhookDBQ, "userID", validUUID).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -212,6 +220,7 @@ func TestGetJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetJSON(context.Background(), validUUID)
|
||||
|
|
@ -219,6 +228,7 @@ func TestGetJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
_, err := m.GetJSON(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
|
|
@ -241,6 +251,7 @@ func TestGetJSON(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getWebhookDBQ, "userID", validUUID).Return(nil, tc.dbErr)
|
||||
m := NewManager(db)
|
||||
|
|
@ -254,6 +265,7 @@ func TestGetJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("webhook data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getWebhookDBQ, "userID", validUUID).Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -269,6 +281,7 @@ func TestGetOwnedByOrgJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetOwnedByOrgJSON(context.Background(), "orgName")
|
||||
|
|
@ -276,12 +289,14 @@ func TestGetOwnedByOrgJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid input", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
_, err := m.GetOwnedByOrgJSON(ctx, "")
|
||||
assert.True(t, errors.Is(err, hub.ErrInvalidInput))
|
||||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgWebhooksDBQ, "userID", "orgName").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -293,6 +308,7 @@ func TestGetOwnedByOrgJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("org webhooks data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getOrgWebhooksDBQ, "userID", "orgName").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -308,6 +324,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
ctx := context.WithValue(context.Background(), hub.UserIDKey, "userID")
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_, _ = m.GetOwnedByUserJSON(context.Background())
|
||||
|
|
@ -315,6 +332,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserWebhooksDBQ, "userID").Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -326,6 +344,7 @@ func TestGetOwnedByUserJSON(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("user webhooks data returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getUserWebhooksDBQ, "userID").Return([]byte("dataJSON"), nil)
|
||||
m := NewManager(db)
|
||||
|
|
@ -360,6 +379,7 @@ func TestGetSubscribedTo(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
|
||||
webhooks, err := m.GetSubscribedTo(ctx, tc.e)
|
||||
|
|
@ -371,6 +391,7 @@ func TestGetSubscribedTo(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("database error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getWebhooksSubscribedToPkgDBQ, hub.NewRelease, validUUID).Return(nil, tests.ErrFakeDB)
|
||||
m := NewManager(db)
|
||||
|
|
@ -382,6 +403,7 @@ func TestGetSubscribedTo(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("webhooks returned successfully", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("QueryRow", ctx, getWebhooksSubscribedToPkgDBQ, hub.NewRelease, validUUID).Return([]byte(`
|
||||
[{
|
||||
|
|
@ -423,6 +445,7 @@ func TestUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("user id not found in ctx", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
assert.Panics(t, func() {
|
||||
_ = m.Update(context.Background(), wh)
|
||||
|
|
@ -505,6 +528,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.errMsg, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := NewManager(nil)
|
||||
|
||||
err := m.Update(ctx, tc.wh)
|
||||
|
|
@ -531,6 +555,7 @@ func TestUpdate(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.dbErr.Error(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateWebhookDBQ, "userID", mock.Anything).Return(tc.dbErr)
|
||||
m := NewManager(db)
|
||||
|
|
@ -543,6 +568,7 @@ func TestUpdate(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("update webhook succeeded", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := &tests.DBMock{}
|
||||
db.On("Exec", ctx, updateWebhookDBQ, "userID", mock.Anything).Return(nil)
|
||||
m := NewManager(db)
|
||||
|
|
|
|||
Loading…
Reference in New Issue