forgejo-sdk/forgejo/repo_action_test.go

40 lines
1.2 KiB
Go

package forgejo
import (
"github.com/stretchr/testify/assert"
"log"
"net/http"
"testing"
)
func TestCreateRepoActionSecret(t *testing.T) {
log.Println("== TestCreateRepoActionSecret ==")
c := newTestClient()
user := createTestUser(t, "action_user", c)
c.SetSudo(user.UserName)
repo, _, err := c.CreateRepo(CreateRepoOption{Name: "Action"})
assert.NoError(t, err)
assert.NotNil(t, repo)
// create repo secret
resp, err := c.CreateRepoActionSecret(user.UserName, repo.Name, CreateSecretOption{Name: "test", Data: "test"})
assert.NoError(t, err)
assert.Equal(t, http.StatusCreated, resp.StatusCode)
// update repo secret
resp, err = c.CreateRepoActionSecret(user.UserName, repo.Name, CreateSecretOption{Name: "test", Data: "test2"})
assert.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
// list repo secrets
secrets, _, err := c.ListRepoActionSecret(user.UserName, repo.Name, ListRepoActionSecretOption{})
assert.NoError(t, err)
assert.Len(t, secrets, 1)
// delete repo secret
resp, err = c.DeleteRepoActionSecret(user.UserName, repo.Name, "test")
assert.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
}