|
| 1 | +// Copyright 2020 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package gitea |
| 6 | + |
| 7 | +import ( |
| 8 | + "log" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestTags(t *testing.T) { |
| 15 | + log.Println("== TestTags ==") |
| 16 | + c := newTestClient() |
| 17 | + |
| 18 | + repo, _ := createTestRepo(t, "TestTags", c) |
| 19 | + |
| 20 | + // Create Tags |
| 21 | + createTestTag(t, c, repo, "tag1") |
| 22 | + |
| 23 | + tags, _, err := c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{}) |
| 24 | + assert.NoError(t, err) |
| 25 | + assert.Len(t, tags, 1) |
| 26 | + |
| 27 | + // DeleteReleaseTag |
| 28 | + resp, err := c.DeleteTag(repo.Owner.UserName, repo.Name, "tag1") |
| 29 | + assert.NoError(t, err) |
| 30 | + assert.EqualValues(t, 204, resp.StatusCode) |
| 31 | + tags, _, err = c.ListRepoTags(repo.Owner.UserName, repo.Name, ListRepoTagsOptions{}) |
| 32 | + assert.NoError(t, err) |
| 33 | + assert.Len(t, tags, 0) |
| 34 | +} |
| 35 | + |
| 36 | +// createTestTag use create release api since there exist no api to create tag only |
| 37 | +// https://github.com/go-gitea/gitea/issues/14669 |
| 38 | +func createTestTag(t *testing.T, c *Client, repo *Repository, name string) { |
| 39 | + rel, _, err := c.CreateRelease(repo.Owner.UserName, repo.Name, CreateReleaseOption{ |
| 40 | + TagName: name, |
| 41 | + Target: "master", |
| 42 | + Title: "TMP Release", |
| 43 | + }) |
| 44 | + assert.NoError(t, err) |
| 45 | + _, err = c.DeleteRelease(repo.Owner.UserName, repo.Name, rel.ID) |
| 46 | + assert.NoError(t, err) |
| 47 | +} |
0 commit comments