Skip to content

Commit 925681d

Browse files
committed
feat: One main added
- Factory function created for object creation - Commands migrated to strategy module - Common interface is created - Each client implemeted common interface alioss, azurebs, gcs, s3 - Test are refactored based on common interface - Dav client still not integrated into main since it has different implementation
1 parent 33eb49f commit 925681d

39 files changed

+536
-791
lines changed

.github/scripts/gcs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ test-int:
8787
export MULTIREGIONAL_BUCKET_NAME="$$(cat $(TMP_DIR)/multiregional.lock)" && \
8888
export REGIONAL_BUCKET_NAME="$$(cat $(TMP_DIR)/regional.lock)" && \
8989
export PUBLIC_BUCKET_NAME="$$(cat $(TMP_DIR)/public.lock)" && \
90+
export SKIP_LONG_TESTS="" && \
9091
cd ../../.. && go run github.com/onsi/ginkgo/v2/ginkgo gcs/integration/
9192

9293
# Perform all non-long tests, including integration tests.

.github/scripts/s3/run-integration-aws-iam.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ trap "cat ${lambda_log}" EXIT
3333
# Go to the repository root (3 levels up from script directory)
3434

3535
pushd "${repo_root}" > /dev/null
36-
36+
export CGO_ENABLED=0
37+
export GOOS=linux
38+
export GOARCH=amd64
3739
echo -e "\n building artifact with $(go version)..."
38-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o out/s3cli ./s3
39-
CGO_ENABLED=0 ginkgo build s3/integration
40+
go build -o out/s3cli
41+
ginkgo build s3/integration
4042

4143
zip -j payload.zip s3/integration/integration.test out/s3cli ${script_dir}/assets/lambda_function.py
4244

@@ -51,6 +53,7 @@ pushd "${repo_root}" > /dev/null
5153
--handler lambda_function.test_runner_handler \
5254
--runtime python3.9
5355

56+
echo "Create done, invoking Lambda function ${lambda_function_name}..."
5457
set +e
5558
tries=0
5659
get_function_status_command="aws lambda get-function --region ${region_name} --function-name ${lambda_function_name}"

alioss/client/client.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package client
33
import (
44
"crypto/md5"
55
"encoding/base64"
6+
"errors"
67
"fmt"
78
"io"
89
"log"
910
"os"
1011
"strings"
12+
"time"
1113
)
1214

1315
type AliBlobstore struct {
@@ -33,8 +35,8 @@ func (client *AliBlobstore) Put(sourceFilePath string, destinationObject string)
3335
return nil
3436
}
3537

36-
func (client *AliBlobstore) Get(sourceObject string, destinationFilePath string) error {
37-
return client.storageClient.Download(sourceObject, destinationFilePath)
38+
func (client *AliBlobstore) Get(sourceObject string, dest string) error {
39+
return client.storageClient.Download(sourceObject, dest)
3840
}
3941

4042
func (client *AliBlobstore) Delete(object string) error {
@@ -45,8 +47,9 @@ func (client *AliBlobstore) Exists(object string) (bool, error) {
4547
return client.storageClient.Exists(object)
4648
}
4749

48-
func (client *AliBlobstore) Sign(object string, action string, expiredInSec int64) (string, error) {
50+
func (client *AliBlobstore) Sign(object string, action string, expiration time.Duration) (string, error) {
4951
action = strings.ToUpper(action)
52+
expiredInSec := int64(expiration.Seconds())
5053
switch action {
5154
case "PUT":
5255
return client.storageClient.SignedUrlPut(object, expiredInSec)
@@ -75,3 +78,23 @@ func (client *AliBlobstore) getMD5(filePath string) (string, error) {
7578

7679
return md5, nil
7780
}
81+
82+
func (client *AliBlobstore) List(prefix string) ([]string, error) {
83+
return nil, errors.New("Not implemented")
84+
}
85+
86+
func (client *AliBlobstore) Copy(srcBlob string, dstBlob string) error {
87+
return errors.New("Not implemented")
88+
}
89+
90+
func (client *AliBlobstore) Properties(dest string) error {
91+
return errors.New("Not implemented")
92+
}
93+
94+
func (client *AliBlobstore) EnsureStorageExists() error {
95+
return errors.New("Not implemented")
96+
}
97+
98+
func (client *AliBlobstore) DeleteRecursive(prefix string) error {
99+
return errors.New("Not implemented")
100+
}

alioss/client/client_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client_test
33
import (
44
"errors"
55
"os"
6+
"time"
67

78
"github.com/cloudfoundry/storage-cli/alioss/client"
89
"github.com/cloudfoundry/storage-cli/alioss/client/clientfakes"
@@ -110,19 +111,25 @@ var _ = Describe("Client", func() {
110111
})
111112

112113
Context("signed url", func() {
114+
var time_sec time.Duration
115+
116+
BeforeEach(func() {
117+
time_sec = 100 * time.Second
118+
})
119+
113120
It("returns a signed url for action 'get'", func() {
114121
storageClient := clientfakes.FakeStorageClient{}
115122
storageClient.SignedUrlGetReturns("https://the-signed-url", nil)
116123

117124
aliBlobstore, err := client.New(&storageClient)
118125
Expect(err).NotTo(HaveOccurred())
119-
url, err := aliBlobstore.Sign("blob", "get", 100)
126+
url, err := aliBlobstore.Sign("blob", "get", time_sec)
120127
Expect(url == "https://the-signed-url").To(BeTrue())
121128
Expect(err).ToNot(HaveOccurred())
122129

123130
object, expiration := storageClient.SignedUrlGetArgsForCall(0)
124131
Expect(object).To(Equal("blob"))
125-
Expect(int(expiration)).To(Equal(100))
132+
Expect(int(expiration)).To(Equal(int(time_sec.Seconds())))
126133
})
127134

128135
It("returns a signed url for action 'put'", func() {
@@ -131,13 +138,13 @@ var _ = Describe("Client", func() {
131138

132139
aliBlobstore, err := client.New(&storageClient)
133140
Expect(err).NotTo(HaveOccurred())
134-
url, err := aliBlobstore.Sign("blob", "put", 100)
141+
url, err := aliBlobstore.Sign("blob", "put", time_sec)
135142
Expect(url == "https://the-signed-url").To(BeTrue())
136143
Expect(err).ToNot(HaveOccurred())
137144

138145
object, expiration := storageClient.SignedUrlPutArgsForCall(0)
139146
Expect(object).To(Equal("blob"))
140-
Expect(int(expiration)).To(Equal(100))
147+
Expect(int(expiration)).To(Equal(int(time_sec.Seconds())))
141148
})
142149

143150
It("fails on unknown action", func() {
@@ -146,7 +153,7 @@ var _ = Describe("Client", func() {
146153

147154
aliBlobstore, err := client.New(&storageClient)
148155
Expect(err).NotTo(HaveOccurred())
149-
url, err := aliBlobstore.Sign("blob", "unknown", 100)
156+
url, err := aliBlobstore.Sign("blob", "unknown", time_sec)
150157
Expect(url).To(Equal(""))
151158
Expect(err).To(HaveOccurred())
152159

alioss/integration/general_ali_test.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var _ = Describe("General testing for all Ali regions", func() {
1717
var blobName string
1818
var configPath string
1919
var contentFile string
20+
var storageType = "alioss"
2021

2122
BeforeEach(func() {
2223
blobName = integration.GenerateRandomString()
@@ -32,16 +33,16 @@ var _ = Describe("General testing for all Ali regions", func() {
3233
Describe("Invoking `put`", func() {
3334
It("uploads a file", func() {
3435
defer func() {
35-
cliSession, err := integration.RunCli(cliPath, configPath, "delete", blobName)
36+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "delete", blobName)
3637
Expect(err).ToNot(HaveOccurred())
3738
Expect(cliSession.ExitCode()).To(BeZero())
3839
}()
3940

40-
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
41+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
4142
Expect(err).ToNot(HaveOccurred())
4243
Expect(cliSession.ExitCode()).To(BeZero())
4344

44-
cliSession, err = integration.RunCli(cliPath, configPath, "exists", blobName)
45+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "exists", blobName)
4546
Expect(err).ToNot(HaveOccurred())
4647
Expect(cliSession.ExitCode()).To(BeZero())
4748

@@ -50,7 +51,7 @@ var _ = Describe("General testing for all Ali regions", func() {
5051

5152
It("overwrites an existing file", func() {
5253
defer func() {
53-
cliSession, err := integration.RunCli(cliPath, configPath, "delete", blobName)
54+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "delete", blobName)
5455
Expect(err).ToNot(HaveOccurred())
5556
Expect(cliSession.ExitCode()).To(BeZero())
5657
}()
@@ -60,23 +61,23 @@ var _ = Describe("General testing for all Ali regions", func() {
6061
defer func() { _ = os.Remove(tmpLocalFile.Name()) }() //nolint:errcheck
6162

6263
contentFile = integration.MakeContentFile("initial content")
63-
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
64+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
6465
Expect(err).ToNot(HaveOccurred())
6566
Expect(cliSession.ExitCode()).To(BeZero())
6667

67-
cliSession, err = integration.RunCli(cliPath, configPath, "get", blobName, tmpLocalFile.Name())
68+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "get", blobName, tmpLocalFile.Name())
6869
Expect(err).ToNot(HaveOccurred())
6970
Expect(cliSession.ExitCode()).To(BeZero())
7071

7172
gottenBytes, _ := os.ReadFile(tmpLocalFile.Name()) //nolint:errcheck
7273
Expect(string(gottenBytes)).To(Equal("initial content"))
7374

7475
contentFile = integration.MakeContentFile("updated content")
75-
cliSession, err = integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
76+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
7677
Expect(err).ToNot(HaveOccurred())
7778
Expect(cliSession.ExitCode()).To(BeZero())
7879

79-
cliSession, err = integration.RunCli(cliPath, configPath, "get", blobName, tmpLocalFile.Name())
80+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "get", blobName, tmpLocalFile.Name())
8081
Expect(err).ToNot(HaveOccurred())
8182
Expect(cliSession.ExitCode()).To(BeZero())
8283

@@ -94,7 +95,7 @@ var _ = Describe("General testing for all Ali regions", func() {
9495

9596
configPath = integration.MakeConfigFile(cfg)
9697

97-
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
98+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
9899
Expect(err).ToNot(HaveOccurred())
99100
Expect(cliSession.ExitCode()).To(Equal(1))
100101

@@ -108,18 +109,18 @@ var _ = Describe("General testing for all Ali regions", func() {
108109
outputFilePath := "/tmp/" + integration.GenerateRandomString()
109110

110111
defer func() {
111-
cliSession, err := integration.RunCli(cliPath, configPath, "delete", blobName)
112+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "delete", blobName)
112113
Expect(err).ToNot(HaveOccurred())
113114
Expect(cliSession.ExitCode()).To(BeZero())
114115

115116
_ = os.Remove(outputFilePath) //nolint:errcheck
116117
}()
117118

118-
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
119+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
119120
Expect(err).ToNot(HaveOccurred())
120121
Expect(cliSession.ExitCode()).To(BeZero())
121122

122-
cliSession, err = integration.RunCli(cliPath, configPath, "get", blobName, outputFilePath)
123+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "get", blobName, outputFilePath)
123124
Expect(err).ToNot(HaveOccurred())
124125
Expect(cliSession.ExitCode()).To(BeZero())
125126

@@ -131,20 +132,20 @@ var _ = Describe("General testing for all Ali regions", func() {
131132
Describe("Invoking `delete`", func() {
132133
It("deletes a file", func() {
133134
defer func() {
134-
cliSession, err := integration.RunCli(cliPath, configPath, "delete", blobName)
135+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "delete", blobName)
135136
Expect(err).ToNot(HaveOccurred())
136137
Expect(cliSession.ExitCode()).To(BeZero())
137138
}()
138139

139-
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
140+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
140141
Expect(err).ToNot(HaveOccurred())
141142
Expect(cliSession.ExitCode()).To(BeZero())
142143

143-
cliSession, err = integration.RunCli(cliPath, configPath, "delete", blobName)
144+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "delete", blobName)
144145
Expect(err).ToNot(HaveOccurred())
145146
Expect(cliSession.ExitCode()).To(BeZero())
146147

147-
cliSession, err = integration.RunCli(cliPath, configPath, "exists", blobName)
148+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "exists", blobName)
148149
Expect(err).ToNot(HaveOccurred())
149150
Expect(cliSession.ExitCode()).To(Equal(3))
150151
})
@@ -153,45 +154,45 @@ var _ = Describe("General testing for all Ali regions", func() {
153154
Describe("Invoking `exists`", func() {
154155
It("returns 0 for an existing blob", func() {
155156
defer func() {
156-
cliSession, err := integration.RunCli(cliPath, configPath, "delete", blobName)
157+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "delete", blobName)
157158
Expect(err).ToNot(HaveOccurred())
158159
Expect(cliSession.ExitCode()).To(BeZero())
159160
}()
160161

161-
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
162+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "put", contentFile, blobName)
162163
Expect(err).ToNot(HaveOccurred())
163164
Expect(cliSession.ExitCode()).To(BeZero())
164165

165-
cliSession, err = integration.RunCli(cliPath, configPath, "exists", blobName)
166+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "exists", blobName)
166167
Expect(err).ToNot(HaveOccurred())
167168
Expect(cliSession.ExitCode()).To(Equal(0))
168169
})
169170

170171
It("returns 3 for a not existing blob", func() {
171-
cliSession, err := integration.RunCli(cliPath, configPath, "exists", blobName)
172+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "exists", blobName)
172173
Expect(err).ToNot(HaveOccurred())
173174
Expect(cliSession.ExitCode()).To(Equal(3))
174175
})
175176
})
176177

177178
Describe("Invoking `sign`", func() {
178179
It("returns 0 for an existing blob", func() {
179-
cliSession, err := integration.RunCli(cliPath, configPath, "sign", "some-blob", "get", "60s")
180+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "sign", "some-blob", "get", "60s")
180181
Expect(err).ToNot(HaveOccurred())
181182
Expect(cliSession.ExitCode()).To(BeZero())
182183

183184
getUrl := bytes.NewBuffer(cliSession.Out.Contents()).String()
184185
Expect(getUrl).To(MatchRegexp("http://" + bucketName + "." + endpoint + "/some-blob"))
185186

186-
cliSession, err = integration.RunCli(cliPath, configPath, "sign", "some-blob", "put", "60s")
187+
cliSession, err = integration.RunCli(cliPath, configPath, storageType, "sign", "some-blob", "put", "60s")
187188
Expect(err).ToNot(HaveOccurred())
188189

189190
putUrl := bytes.NewBuffer(cliSession.Out.Contents()).String()
190191
Expect(putUrl).To(MatchRegexp("http://" + bucketName + "." + endpoint + "/some-blob"))
191192
})
192193

193194
It("returns 3 for a not existing blob", func() {
194-
cliSession, err := integration.RunCli(cliPath, configPath, "exists", blobName)
195+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "exists", blobName)
195196
Expect(err).ToNot(HaveOccurred())
196197
Expect(cliSession.ExitCode()).To(Equal(3))
197198
})
@@ -202,7 +203,7 @@ var _ = Describe("General testing for all Ali regions", func() {
202203
configPath := integration.MakeConfigFile(&defaultConfig)
203204
defer func() { _ = os.Remove(configPath) }() //nolint:errcheck
204205

205-
cliSession, err := integration.RunCli(cliPath, configPath, "-v")
206+
cliSession, err := integration.RunCli(cliPath, configPath, storageType, "-v")
206207
Expect(err).ToNot(HaveOccurred())
207208
Expect(cliSession.ExitCode()).To(Equal(0))
208209

alioss/integration/integration_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var defaultConfig config.AliStorageConfig
2626
var _ = BeforeSuite(func() {
2727
if len(cliPath) == 0 {
2828
var err error
29-
cliPath, err = gexec.Build("github.com/cloudfoundry/storage-cli/alioss")
29+
cliPath, err = gexec.Build("github.com/cloudfoundry/storage-cli")
3030
Expect(err).ShouldNot(HaveOccurred())
3131
}
3232

alioss/integration/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ func MakeContentFile(content string) string {
5151
return tmpFile.Name()
5252
}
5353

54-
func RunCli(cliPath string, configPath string, subcommand string, args ...string) (*gexec.Session, error) {
54+
func RunCli(cliPath string, configPath string, storageType string, subcommand string, args ...string) (*gexec.Session, error) {
5555
cmdArgs := []string{
5656
"-c",
5757
configPath,
58+
"-s",
59+
storageType,
5860
subcommand,
5961
}
6062
cmdArgs = append(cmdArgs, args...)

0 commit comments

Comments
 (0)