mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Backport #32974 by Zettat123 Co-authored-by: Zettat123 <zettat123@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -70,7 +70,7 @@ func (a *azureBlobObject) Seek(offset int64, whence int) (int64, error) {
 | 
			
		||||
	case io.SeekCurrent:
 | 
			
		||||
		offset += a.offset
 | 
			
		||||
	case io.SeekEnd:
 | 
			
		||||
		offset = a.Size - offset
 | 
			
		||||
		offset = a.Size + offset
 | 
			
		||||
	default:
 | 
			
		||||
		return 0, errors.New("Seek: invalid whence")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,8 @@
 | 
			
		||||
package storage
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
@@ -54,3 +56,46 @@ func TestAzureBlobStoragePath(t *testing.T) {
 | 
			
		||||
	assert.Equal(t, "base/a", m.buildAzureBlobPath("/a"))
 | 
			
		||||
	assert.Equal(t, "base/a/b", m.buildAzureBlobPath("/a/b/"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Test_azureBlobObject(t *testing.T) {
 | 
			
		||||
	if os.Getenv("CI") == "" {
 | 
			
		||||
		t.Skip("azureBlobStorage not present outside of CI")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	s, err := NewStorage(setting.AzureBlobStorageType, &setting.Storage{
 | 
			
		||||
		AzureBlobConfig: setting.AzureBlobStorageConfig{
 | 
			
		||||
			// https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio-code#ip-style-url
 | 
			
		||||
			Endpoint: "http://devstoreaccount1.azurite.local:10000",
 | 
			
		||||
			// https://learn.microsoft.com/azure/storage/common/storage-use-azurite?tabs=visual-studio-code#well-known-storage-account-and-key
 | 
			
		||||
			AccountName: "devstoreaccount1",
 | 
			
		||||
			AccountKey:  "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
 | 
			
		||||
			Container:   "test",
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
 | 
			
		||||
	data := "Q2xTckt6Y1hDOWh0"
 | 
			
		||||
	_, err = s.Save("test.txt", bytes.NewBufferString(data), int64(len(data)))
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	obj, err := s.Open("test.txt")
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	offset, err := obj.Seek(2, io.SeekStart)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.EqualValues(t, 2, offset)
 | 
			
		||||
	buf1 := make([]byte, 3)
 | 
			
		||||
	read, err := obj.Read(buf1)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.EqualValues(t, 3, read)
 | 
			
		||||
	assert.Equal(t, data[2:5], string(buf1))
 | 
			
		||||
	offset, err = obj.Seek(-5, io.SeekEnd)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.EqualValues(t, len(data)-5, offset)
 | 
			
		||||
	buf2 := make([]byte, 4)
 | 
			
		||||
	read, err = obj.Read(buf2)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.EqualValues(t, 4, read)
 | 
			
		||||
	assert.Equal(t, data[11:15], string(buf2))
 | 
			
		||||
	assert.NoError(t, obj.Close())
 | 
			
		||||
	assert.NoError(t, s.Delete("test.txt"))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user