forgejo-sdk/gitea/repo_file_test.go
6543 8045079a7a Add Get/Update/Create File (#281)
remove -binding- since sdk dont use it

Merge branch 'master' into add-edit-file

fix test

Merge branch 'master' into add-edit-file

add TEST

add Get/Create/Update-Contents

add missing structs

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/281
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
2020-04-01 02:39:20 +00:00

53 lines
1.6 KiB
Go

// Copyright 2020 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 gitea
import (
"encoding/base64"
"log"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFileCreateUpdateGet(t *testing.T) {
log.Println("== TestFileCreateUpdateGet ==")
c := newTestClient()
repo, err := createTestRepo(t, "ChangeFiles", c)
assert.NoError(t, err)
assert.NotNil(t, repo)
raw, err := c.GetFile(repo.Owner.UserName, repo.Name, "master", "README.md")
assert.NoError(t, err)
assert.EqualValues(t, "IyBDaGFuZ2VGaWxlcwoKQSB0ZXN0IFJlcG86IENoYW5nZUZpbGVz", base64.StdEncoding.EncodeToString(raw))
newFile, err := c.CreateFile(repo.Owner.UserName, repo.Name, "A", CreateFileOptions{
FileOptions: FileOptions{
Message: "create file A",
},
Content: "ZmlsZUEK",
})
assert.NoError(t, err)
raw, _ = c.GetFile(repo.Owner.UserName, repo.Name, "master", "A")
assert.EqualValues(t, "ZmlsZUEK", base64.StdEncoding.EncodeToString(raw))
updatedFile, err := c.UpdateFile(repo.Owner.UserName, repo.Name, "A", UpdateFileOptions{
DeleteFileOptions: DeleteFileOptions{
FileOptions: FileOptions{
Message: "add a new line",
},
SHA: newFile.Content.SHA,
},
Content: "ZmlsZUEKCmFuZCBhIG5ldyBsaW5lCg==",
})
assert.NoError(t, err)
assert.NotNil(t, updatedFile)
file, err := c.GetContents(repo.Owner.UserName, repo.Name, "master", "A")
assert.NoError(t, err)
assert.EqualValues(t, updatedFile.Content.SHA, file.SHA)
assert.EqualValues(t, &updatedFile.Content.Content, &file.Content)
}