Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

feat: Setup Integration tests #4

Merged
merged 8 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export STORAGE_AZFILE_INTEGRATION_TEST=on
export STORAGE_AZFILE_CREDENTIAL=hmac:account_name:account_key
export STORAGE_AZFILE_NAME=sharename
export STORAGE_AZFILE_ENDPOINT=https:accountname.file.core.windows.net
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## go-service-azfile
[![Build Status](https://github.com/beyondstorage/go-service-azfile/workflows/Unit%20Test/badge.svg?branch=master)](https://github.com/beyondstorage/go-service-azfile/actions?query=workflow%3A%22Unit+Test%22)
[![Integration Tests](https://teamcity.beyondstorage.io/app/rest/builds/buildType:(id:Services_Azfile_IntegrationTest)/statusIcon)](https://teamcity.beyondstorage.io/buildConfiguration/Services_Azfile_IntegrationTest)
[![License](https://img.shields.io/badge/license-apache%20v2-blue.svg)](https://github.com/Xuanwo/storage/blob/master/LICENSE)
[![](https://img.shields.io/matrix/beyondstorage@go-storage:matrix.org.svg?logo=matrix)](https://matrix.to/#/#beyondstorage@go-storage:matrix.org)

azfile service support for [go-storage](https://github.com/beyondstorage/go-storage)
# go-services-azfile

[Azure Files](https://azure.microsoft.com/en-us/services/storage/files/) service support for [go-storage](https://github.com/beyondstorage/go-storage)

## Install

```go
go get github.com/beyondstorage/go-service-azfile
```
31 changes: 29 additions & 2 deletions generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ go 1.15
require (
github.com/Azure/azure-storage-file-go v0.8.0
github.com/beyondstorage/go-endpoint v1.1.0
github.com/beyondstorage/go-storage/v4 v4.6.0
github.com/beyondstorage/go-integration-test/v4 v4.4.0
github.com/beyondstorage/go-storage/v4 v4.7.0
github.com/google/uuid v1.3.0
github.com/pkg/errors v0.9.1 // indirect
)
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ github.com/Xuanwo/templateutils v0.1.0 h1:WpkWOqQtIQ2vAIpJLa727DdN8WtxhUkkbDGa6U
github.com/Xuanwo/templateutils v0.1.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8=
github.com/beyondstorage/go-endpoint v1.1.0 h1:cpjmQdrAMyaLoT161NIFU/eXcsuMI3xViycid5/mBZg=
github.com/beyondstorage/go-endpoint v1.1.0/go.mod h1:P2hknaGrziOJJKySv/XnAiVw/d3v12/LZu2gSxEx4nM=
github.com/beyondstorage/go-storage/v4 v4.6.0 h1:a05dtbYjMZB7LrUSvVzzHwlx33B4yEmd5oQB7Itk7VY=
github.com/beyondstorage/go-storage/v4 v4.6.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw=
github.com/beyondstorage/go-integration-test/v4 v4.4.0 h1:wiItWmhoAY71Fp76u6u95jJn5m6swM9N/xNV9mW7nyI=
github.com/beyondstorage/go-integration-test/v4 v4.4.0/go.mod h1:o0pHhyaRR/OO6QxnRqWW3aFjTycBZjoKSdHKN/JZRjo=
github.com/beyondstorage/go-storage/v4 v4.7.0 h1:7hpRFNoPY0vWRSH/p2biD2dUQdZMrs1TuIkkqDefmCE=
github.com/beyondstorage/go-storage/v4 v4.7.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw=
github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY=
github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU=
github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ=
Expand All @@ -22,7 +24,11 @@ github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+Licev
github.com/google/pprof v0.0.0-20181127221834-b4f47329b966/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kevinburke/go-bindata v3.22.0+incompatible h1:/JmqEhIWQ7GRScV0WjX/0tqBrC5D21ALg0H0U/KZ/ts=
github.com/kevinburke/go-bindata v3.22.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand All @@ -43,6 +49,10 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand All @@ -55,6 +65,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -78,6 +89,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
Expand Down
6 changes: 3 additions & 3 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *Storage) createDir(ctx context.Context, path string, opt pairStorageCre
return nil, err
} else {
// The directory not exists, we should create the directory.
_, err = s.client.NewDirectoryURL(path).Create(ctx, nil, properties)
_, err = s.client.NewDirectoryURL(path).Create(ctx, azfile.Metadata{}, properties)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (s *Storage) delete(ctx context.Context, path string, opt pairStorageDelete
func (s *Storage) list(ctx context.Context, path string, opt pairStorageList) (oi *ObjectIterator, err error) {
input := &objectPageStatus{
maxResults: 200,
prefix: s.getAbsPath(path),
prefix: path,
}

return NewObjectIterator(ctx, s.nextObjectPage, input), nil
Expand Down Expand Up @@ -244,7 +244,7 @@ func (s *Storage) write(ctx context.Context, path string, r io.Reader, size int6

// `Create` only initializes the file.
// ref: https://docs.microsoft.com/en-us/rest/api/storageservices/create-file
_, err = s.client.NewFileURL(path).Create(ctx, size, headers, nil)
_, err = s.client.NewFileURL(path).Create(ctx, size, headers, azfile.Metadata{})
if err != nil {
return 0, err
}
Expand Down
32 changes: 32 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## How run azfile integration tests

### Run tests locally

Copy example files and update corresponding values.

```shell
cp Makefile.env.exmaple Makefile.env
```

Run tests

```shell
make integration_test
```

### Run tests in CI

Set following environment variables:

```shell
export STORAGE_AZFILE_INTEGRATION_TEST=on
export STORAGE_AZFILE_CREDENTIAL=hmac:account_name:account_key
export STORAGE_AZFILE_NAME=sharename
export STORAGE_AZFILE_ENDPOINT=https:accountname.file.core.windows.net
```

Run tests

```shell
make integration_test
```
22 changes: 22 additions & 0 deletions tests/storage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tests

import (
"os"
"testing"

tests "github.com/beyondstorage/go-integration-test/v4"
)

func TestStorage(t *testing.T) {
if os.Getenv("STORAGE_AZFILE_INTEGRATION_TEST") != "on" {
t.Skipf("STORAGE_AZFILE_INTEGRATION_TEST is not 'on', skipped")
}
tests.TestStorager(t, setupTest(t))
}

func TestDir(t *testing.T) {
if os.Getenv("STORAGE_AZFILE_INTEGRATION_TEST") != "on" {
t.Skipf("STORAGE_AZFILE_INTEGRATION_TEST is not 'on', skipped")
}
tests.TestDirer(t, setupTest(t))
}
27 changes: 27 additions & 0 deletions tests/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tests

import (
"os"
"testing"

"github.com/google/uuid"

azfile "github.com/beyondstorage/go-service-azfile"
ps "github.com/beyondstorage/go-storage/v4/pairs"
"github.com/beyondstorage/go-storage/v4/types"
)

func setupTest(t *testing.T) types.Storager {
t.Log("Setup test for azfile")

store, err := azfile.NewStorager(
ps.WithCredential(os.Getenv("STORAGE_AZFILE_CREDENTIAL")),
ps.WithEndpoint(os.Getenv("STORAGE_AZFILE_ENDPOINT")),
ps.WithWorkDir("/"+uuid.New().String()+"/"),
ps.WithName(os.Getenv("STORAGE_AZFILE_NAME")),
)
if err != nil {
t.Errorf("new storager: %v", err)
}
return store
}
30 changes: 13 additions & 17 deletions utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package azfile

import (
"context"
"fmt"
"net/url"
"strings"
"time"

"github.com/Azure/azure-storage-file-go/azfile"

Expand Down Expand Up @@ -74,12 +74,6 @@ func newStorager(pairs ...types.Pair) (store *Storage, err error) {
return nil, services.PairUnsupportedError{Pair: ps.WithEndpoint(opt.Endpoint)}
}

if strings.HasPrefix(store.workDir, "/") {
uri = fmt.Sprintln(uri + store.workDir)
} else {
uri = fmt.Sprintln(uri + "/" + store.workDir)
}

primaryURL, _ := url.Parse(uri)

cred, err := credential.Parse(opt.Credential)
Expand All @@ -96,18 +90,20 @@ func newStorager(pairs ...types.Pair) (store *Storage, err error) {
}

p := azfile.NewPipeline(credValue, azfile.PipelineOptions{
Retry: azfile.RetryOptions{
// Use a fixed back-off retry policy.
Policy: 1,
// A value of 1 means 1 try and no retries.
MaxTries: 1,
// Set a long enough timeout to adopt our timeout control.
// This value could be adjusted to context deadline if request context has a deadline set.
TryTimeout: 720 * time.Hour,
},
Retry: azfile.RetryOptions{},
})

store.client = azfile.NewDirectoryURL(*primaryURL, p)
serviceURL := azfile.NewServiceURL(*primaryURL, p)

ctx := context.Background()
shareURL := serviceURL.NewShareURL(opt.Name)

workDir := strings.TrimPrefix(store.workDir, "/")
store.client = shareURL.NewDirectoryURL(workDir)
_, err = store.client.Create(ctx, azfile.Metadata{}, azfile.SMBProperties{})
if err != nil {
return nil, err
}

if opt.HasDefaultStoragePairs {
store.defaultPairs = opt.DefaultStoragePairs
Expand Down