Skip to content

Commit 3b45de7

Browse files
committed
fix test
1 parent f169f57 commit 3b45de7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tests/integration/api_repo_tags_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/models/actions"
1212
auth_model "code.gitea.io/gitea/models/auth"
13+
repo_model "code.gitea.io/gitea/models/repo"
1314
"code.gitea.io/gitea/models/unittest"
1415
user_model "code.gitea.io/gitea/models/user"
1516
"code.gitea.io/gitea/modules/setting"
@@ -23,13 +24,12 @@ import (
2324
func TestAPIRepoTags(t *testing.T) {
2425
defer tests.PrepareTestEnv(t)()
2526
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
27+
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
2628
// Login as User2.
2729
session := loginUser(t, user.Name)
2830
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
2931

30-
repoName := "repo1"
31-
32-
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags", user.Name, repoName).
32+
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags", user.Name, repo1.Name).
3333
AddTokenAuth(token)
3434
resp := MakeRequest(t, req, http.StatusOK)
3535

@@ -44,7 +44,7 @@ func TestAPIRepoTags(t *testing.T) {
4444
assert.Equal(t, setting.AppURL+"user2/repo1/archive/v1.1.zip", tags[0].ZipballURL)
4545
assert.Equal(t, setting.AppURL+"user2/repo1/archive/v1.1.tar.gz", tags[0].TarballURL)
4646

47-
newTag := createNewTagUsingAPI(t, session, token, user.Name, repoName, "gitea/22", "", "nice!\nand some text")
47+
newTag := createNewTagUsingAPI(t, session, token, user.Name, repo1.Name, "gitea/22", "", "nice!\nand some text")
4848
resp = MakeRequest(t, req, http.StatusOK)
4949
DecodeJSON(t, resp, &tags)
5050
assert.Len(t, tags, 2)
@@ -58,15 +58,15 @@ func TestAPIRepoTags(t *testing.T) {
5858
}
5959

6060
// get created tag
61-
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags/%s", user.Name, repoName, newTag.Name).
61+
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags/%s", user.Name, repo1.Name, newTag.Name).
6262
AddTokenAuth(token)
6363
resp = MakeRequest(t, req, http.StatusOK)
6464
var tag *api.Tag
6565
DecodeJSON(t, resp, &tag)
6666
assert.EqualValues(t, newTag, tag)
6767

6868
// delete tag
69-
delReq := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/tags/%s", user.Name, repoName, newTag.Name).
69+
delReq := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/tags/%s", user.Name, repo1.Name, newTag.Name).
7070
AddTokenAuth(token)
7171
MakeRequest(t, delReq, http.StatusNoContent)
7272

@@ -76,14 +76,20 @@ func TestAPIRepoTags(t *testing.T) {
7676
// check action run
7777
tests := []struct {
7878
id int64
79+
ref string
80+
SHA string
7981
event webhook.HookEventType
8082
}{
8183
{
8284
id: 793,
85+
ref: fmt.Sprintf("refs/tags/%s", newTag.Name),
86+
SHA: newTag.Commit.SHA,
8387
event: webhook.HookEventCreate,
8488
},
8589
{
8690
id: 794,
91+
ref: repo1.DefaultBranch,
92+
SHA: "94dc45d6ec51090b36c4d5bd5d9e6f5a70da9edf",
8793
event: webhook.HookEventDelete,
8894
},
8995
}
@@ -92,9 +98,9 @@ func TestAPIRepoTags(t *testing.T) {
9298
assert.NotNil(t, run)
9399
assert.Equal(t, int64(1), run.RepoID)
94100
assert.Equal(t, "test.yaml", run.WorkflowID)
95-
assert.Equal(t, newTag.Commit.SHA, run.CommitSHA)
101+
assert.Equal(t, tt.SHA, run.CommitSHA)
96102
assert.Equal(t, "add workflow", run.Title)
97-
assert.Equal(t, fmt.Sprintf("refs/tags/%s", newTag.Name), run.Ref)
103+
assert.Equal(t, tt.ref, run.Ref)
98104
assert.Equal(t, tt.event, run.Event)
99105
}
100106
}

0 commit comments

Comments
 (0)