- Add `bytes` and `encoding/json` imports to `org_action.go` - Implement `CreateSecretOption` struct with validation in `org_action.go` - Add `CreateOrgActionSecret` function to create or update organization secrets in `org_action.go` - Create new test file `org_action_test.go` with tests for creating and updating organization secrets - Add `Data` field to `Secret` struct in `secret.go` Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/661 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package forgejo
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCreateOrgActionSecret(t *testing.T) {
|
|
log.Println("== TestCreateOrgActionSecret ==")
|
|
c := newTestClient()
|
|
|
|
user := createTestUser(t, "org_action_user", c)
|
|
c.SetSudo(user.UserName)
|
|
newOrg, _, err := c.CreateOrg(CreateOrgOption{Name: "ActionOrg"})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, newOrg)
|
|
|
|
// create secret
|
|
resp, err := c.CreateOrgActionSecret(newOrg.UserName, CreateSecretOption{Name: "test", Data: "test"})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, http.StatusCreated, resp.StatusCode)
|
|
|
|
// update secret
|
|
resp, err = c.CreateOrgActionSecret(newOrg.UserName, CreateSecretOption{Name: "test", Data: "test2"})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
|
|
|
|
// list secrets
|
|
secrets, _, err := c.ListOrgActionSecret(newOrg.UserName, ListOrgActionSecretOption{})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, secrets, 1)
|
|
}
|