This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to handle the error that the webhook is not found when an user de…
…activates (#254) * Fix the location of entity error * Fix to handle the webhook is not found * Add unit test for github
- Loading branch information
Noah Lee
authored
Dec 8, 2021
1 parent
87f6cfc
commit bb22d1a
Showing
8 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package interactor | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
|
||
"github.com/gitploy-io/gitploy/ent" | ||
"github.com/gitploy-io/gitploy/internal/interactor/mock" | ||
"github.com/gitploy-io/gitploy/pkg/e" | ||
) | ||
|
||
func TestInteractor_DeactivateRepo(t *testing.T) { | ||
t.Run("Deactivate successfully even if the webhook is not found.", func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
store := mock.NewMockStore(ctrl) | ||
scm := mock.NewMockSCM(ctrl) | ||
|
||
t.Log("Mocking DeleteWebhook to return an EntityNotFound error.") | ||
scm. | ||
EXPECT(). | ||
DeleteWebhook(gomock.Any(), gomock.AssignableToTypeOf(&ent.User{}), gomock.AssignableToTypeOf(&ent.Repo{}), gomock.Any()). | ||
Return(e.NewError(e.ErrorCodeEntityNotFound, nil)) | ||
|
||
store. | ||
EXPECT(). | ||
Deactivate(gomock.Any(), gomock.AssignableToTypeOf(&ent.Repo{})). | ||
Return(&ent.Repo{}, nil) | ||
|
||
i := newMockInteractor(store, scm) | ||
|
||
_, err := i.DeactivateRepo(context.Background(), &ent.User{}, &ent.Repo{}) | ||
if err != nil { | ||
t.Fatalf("DeactivateRepo returns an error: %v", err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/gitploy-io/gitploy/ent" | ||
"github.com/gitploy-io/gitploy/pkg/e" | ||
"gopkg.in/h2non/gock.v1" | ||
) | ||
|
||
func TestGithub_DeleteWebhook(t *testing.T) { | ||
t.Run("Return the ErrorCodeEntityNotFound error when the webhook is not found.", func(t *testing.T) { | ||
t.Log("Mocking the delete webhook API") | ||
gock.New("https://api.github.com"). | ||
Delete("/repos/gitploy-io/gitploy/hooks/1"). | ||
Reply(404) | ||
|
||
g := NewGithub(&GithubConfig{}) | ||
|
||
const hookID = 1 | ||
|
||
err := g.DeleteWebhook( | ||
context.Background(), | ||
&ent.User{}, | ||
&ent.Repo{ | ||
Namespace: "gitploy-io", | ||
Name: "gitploy", | ||
}, | ||
hookID, | ||
) | ||
|
||
if !e.HasErrorCode(err, e.ErrorCodeEntityNotFound) { | ||
t.Fatalf("DeleteWebhook doesn't returns an ErrorCodeEntityNotFound error: %v", err) | ||
} | ||
}) | ||
|
||
t.Run("Delete the webhook.", func(t *testing.T) { | ||
t.Log("Mocking the delete webhook API") | ||
gock.New("https://api.github.com"). | ||
Delete("/repos/gitploy-io/gitploy/hooks/1"). | ||
Reply(200) | ||
|
||
g := NewGithub(&GithubConfig{}) | ||
|
||
const hookID = 1 | ||
|
||
err := g.DeleteWebhook( | ||
context.Background(), | ||
&ent.User{}, | ||
&ent.Repo{ | ||
Namespace: "gitploy-io", | ||
Name: "gitploy", | ||
}, | ||
hookID, | ||
) | ||
|
||
if err != nil { | ||
t.Fatalf("DeleteWebhook returns an error: %v", err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters