From 9c940540647f95e747555bc9ba31583751f619d0 Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Mon, 5 Feb 2018 21:43:12 +0900 Subject: [PATCH 1/4] remove package name from func name's prefix around check --- check/check_command.go | 22 ++++++++--------- check/check_command_test.go | 8 +++---- check/models.go | 4 ++-- cmd/check/main.go | 8 +++---- integration/check_test.go | 48 ++++++++++++++++++------------------- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/check/check_command.go b/check/check_command.go index cbabba64..4d04da32 100644 --- a/check/check_command.go +++ b/check/check_command.go @@ -7,19 +7,19 @@ import ( "github.com/concourse/s3-resource/versions" ) -type CheckCommand struct { +type Command struct { s3client s3resource.S3Client } -func NewCheckCommand(s3client s3resource.S3Client) *CheckCommand { - return &CheckCommand{ +func NewCommand(s3client s3resource.S3Client) *Command { + return &Command{ s3client: s3client, } } -func (command *CheckCommand) Run(request CheckRequest) (CheckResponse, error) { +func (command *Command) Run(request Request) (Response, error) { if ok, message := request.Source.IsValid(); !ok { - return CheckResponse{}, errors.New(message) + return Response{}, errors.New(message) } if request.Source.Regexp != "" { @@ -29,7 +29,7 @@ func (command *CheckCommand) Run(request CheckRequest) (CheckResponse, error) { } } -func (command *CheckCommand) checkByRegex(request CheckRequest) CheckResponse { +func (command *Command) checkByRegex(request Request) Response { extractions := versions.GetBucketFileVersions(command.s3client, request.Source) if len(extractions) == 0 { @@ -44,8 +44,8 @@ func (command *CheckCommand) checkByRegex(request CheckRequest) CheckResponse { } } -func (command *CheckCommand) checkByVersionedFile(request CheckRequest) CheckResponse { - response := CheckResponse{} +func (command *Command) checkByVersionedFile(request Request) Response { + response := Response{} bucketVersions, err := command.s3client.BucketFileVersions(request.Source.Bucket, request.Source.VersionedFile) @@ -85,13 +85,13 @@ func (command *CheckCommand) checkByVersionedFile(request CheckRequest) CheckRes return response } -func latestVersion(extractions versions.Extractions) CheckResponse { +func latestVersion(extractions versions.Extractions) Response { lastExtraction := extractions[len(extractions)-1] return []s3resource.Version{{Path: lastExtraction.Path}} } -func newVersions(lastVersion versions.Extraction, extractions versions.Extractions) CheckResponse { - response := CheckResponse{} +func newVersions(lastVersion versions.Extraction, extractions versions.Extractions) Response { + response := Response{} for _, extraction := range extractions { if extraction.Version.Compare(lastVersion.Version) >= 0 { diff --git a/check/check_command_test.go b/check/check_command_test.go index 01ef663b..06f42285 100644 --- a/check/check_command_test.go +++ b/check/check_command_test.go @@ -17,10 +17,10 @@ var _ = Describe("Check Command", func() { Describe("running the command", func() { var ( tmpPath string - request CheckRequest + request Request s3client *fakes.FakeS3Client - command *CheckCommand + command *Command ) BeforeEach(func() { @@ -28,14 +28,14 @@ var _ = Describe("Check Command", func() { tmpPath, err = ioutil.TempDir("", "check_command") Ω(err).ShouldNot(HaveOccurred()) - request = CheckRequest{ + request = Request{ Source: s3resource.Source{ Bucket: "bucket-name", }, } s3client = &fakes.FakeS3Client{} - command = NewCheckCommand(s3client) + command = NewCommand(s3client) s3client.BucketFilesReturns([]string{ "files/abc-0.0.1.tgz", diff --git a/check/models.go b/check/models.go index b0076f5d..6d944029 100644 --- a/check/models.go +++ b/check/models.go @@ -2,9 +2,9 @@ package check import "github.com/concourse/s3-resource" -type CheckRequest struct { +type Request struct { Source s3resource.Source `json:"source"` Version s3resource.Version `json:"version"` } -type CheckResponse []s3resource.Version +type Response []s3resource.Version diff --git a/cmd/check/main.go b/cmd/check/main.go index a9993800..27713734 100644 --- a/cmd/check/main.go +++ b/cmd/check/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - var request check.CheckRequest + var request check.Request inputRequest(&request) awsConfig := s3resource.NewAwsConfig( @@ -28,7 +28,7 @@ func main() { request.Source.UseV2Signing, ) - command := check.NewCheckCommand(client) + command := check.NewCommand(client) response, err := command.Run(request) if err != nil { s3resource.Fatal("running command", err) @@ -37,13 +37,13 @@ func main() { outputResponse(response) } -func inputRequest(request *check.CheckRequest) { +func inputRequest(request *check.Request) { if err := json.NewDecoder(os.Stdin).Decode(request); err != nil { s3resource.Fatal("reading request from stdin", err) } } -func outputResponse(response check.CheckResponse) { +func outputResponse(response check.Response) { if err := json.NewEncoder(os.Stdout).Encode(response); err != nil { s3resource.Fatal("writing response to stdout", err) } diff --git a/integration/check_test.go b/integration/check_test.go index d40a840e..8e235251 100644 --- a/integration/check_test.go +++ b/integration/check_test.go @@ -44,10 +44,10 @@ var _ = Describe("check", func() { }) Context("with a versioned_file and a regex", func() { - var checkRequest check.CheckRequest + var checkRequest check.Request BeforeEach(func() { - checkRequest = check.CheckRequest{ + checkRequest = check.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -74,11 +74,11 @@ var _ = Describe("check", func() { Context("when we do not provide a previous version", func() { var directoryPrefix string - var checkRequest check.CheckRequest + var checkRequest check.Request Context("with a regex", func() { BeforeEach(func() { - checkRequest = check.CheckRequest{ + checkRequest = check.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -118,7 +118,7 @@ var _ = Describe("check", func() { It("returns an empty check response", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) @@ -158,11 +158,11 @@ var _ = Describe("check", func() { It("outputs the path of the latest versioned s3 object", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(check.CheckResponse{ + Ω(response).Should(Equal(check.Response{ { Path: filepath.Join(directoryPrefix, "file-does-match-2"), }, @@ -173,7 +173,7 @@ var _ = Describe("check", func() { Context("with a versioned_file", func() { BeforeEach(func() { - checkRequest = check.CheckRequest{ + checkRequest = check.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -249,7 +249,7 @@ var _ = Describe("check", func() { It("returns an empty check response", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) @@ -293,14 +293,14 @@ var _ = Describe("check", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) fileVersions, err := s3client.BucketFileVersions(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file")) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(check.CheckResponse{ + Ω(response).Should(Equal(check.Response{ { VersionID: fileVersions[0], }, @@ -312,11 +312,11 @@ var _ = Describe("check", func() { Context("when we provide a previous version", func() { var directoryPrefix string - var checkRequest check.CheckRequest + var checkRequest check.Request Context("with a regex", func() { BeforeEach(func() { - checkRequest = check.CheckRequest{ + checkRequest = check.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -356,7 +356,7 @@ var _ = Describe("check", func() { It("returns an empty check response", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) @@ -403,11 +403,11 @@ var _ = Describe("check", func() { It("outputs the path of the latest versioned s3 object", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(check.CheckResponse{ + Ω(response).Should(Equal(check.Response{ { Path: filepath.Join(directoryPrefix, "file-does-match-2"), }, @@ -463,11 +463,11 @@ var _ = Describe("check", func() { It("outputs the path of the latest versioned s3 object", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(check.CheckResponse{ + Ω(response).Should(Equal(check.Response{ { Path: filepath.Join(directoryPrefix, "file-1.2.0-rc.2"), }, @@ -479,7 +479,7 @@ var _ = Describe("check", func() { Context("with a versioned_file", func() { BeforeEach(func() { - checkRequest = check.CheckRequest{ + checkRequest = check.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -528,7 +528,7 @@ var _ = Describe("check", func() { It("returns an empty check response", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) @@ -580,14 +580,14 @@ var _ = Describe("check", func() { It("returns the most recent version", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) fileVersions, err := s3client.BucketFileVersions(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file")) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(check.CheckResponse{ + Ω(response).Should(Equal(check.Response{ { VersionID: fileVersions[1], }, @@ -646,11 +646,11 @@ var _ = Describe("check", func() { It("returns the next most recent version", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response check.CheckResponse + var response check.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(check.CheckResponse{ + Ω(response).Should(Equal(check.Response{ { VersionID: fileVersions[1], }, From 2b0a6fe958a7b031738088094b37fdbb3164b67a Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Mon, 5 Feb 2018 22:01:07 +0900 Subject: [PATCH 2/4] remove package name from func name's prefix around in --- cmd/in/main.go | 8 ++++---- in/in_command.go | 42 +++++++++++++++++++++--------------------- in/in_command_test.go | 8 ++++---- in/models.go | 4 ++-- integration/in_test.go | 32 ++++++++++++++++---------------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/cmd/in/main.go b/cmd/in/main.go index 3db3aa43..3d9417ce 100644 --- a/cmd/in/main.go +++ b/cmd/in/main.go @@ -21,7 +21,7 @@ func main() { destinationDir := os.Args[1] - var request in.InRequest + var request in.Request inputRequest(&request) awsConfig := s3resource.NewAwsConfig( @@ -56,7 +56,7 @@ func main() { request.Source.UseV2Signing, ) - command := in.NewInCommand(client) + command := in.NewCommand(client) response, err := command.Run(destinationDir, request) if err != nil { @@ -66,13 +66,13 @@ func main() { outputResponse(response) } -func inputRequest(request *in.InRequest) { +func inputRequest(request *in.Request) { if err := json.NewDecoder(os.Stdin).Decode(request); err != nil { s3resource.Fatal("reading request from stdin", err) } } -func outputResponse(response in.InResponse) { +func outputResponse(response in.Response) { if err := json.NewEncoder(os.Stdout).Encode(response); err != nil { s3resource.Fatal("writing response to stdout", err) } diff --git a/in/in_command.go b/in/in_command.go index c7846aad..a5120cec 100644 --- a/in/in_command.go +++ b/in/in_command.go @@ -18,21 +18,21 @@ type RequestURLProvider struct { s3Client s3resource.S3Client } -func (up *RequestURLProvider) GetURL(request InRequest, remotePath string) string { +func (up *RequestURLProvider) GetURL(request Request, remotePath string) string { return up.s3URL(request, remotePath) } -func (up *RequestURLProvider) s3URL(request InRequest, remotePath string) string { +func (up *RequestURLProvider) s3URL(request Request, remotePath string) string { return up.s3Client.URL(request.Source.Bucket, remotePath, request.Source.Private, request.Version.VersionID) } -type InCommand struct { +type Command struct { s3client s3resource.S3Client urlProvider RequestURLProvider } -func NewInCommand(s3client s3resource.S3Client) *InCommand { - return &InCommand{ +func NewCommand(s3client s3resource.S3Client) *Command { + return &Command{ s3client: s3client, urlProvider: RequestURLProvider{ s3Client: s3client, @@ -40,14 +40,14 @@ func NewInCommand(s3client s3resource.S3Client) *InCommand { } } -func (command *InCommand) Run(destinationDir string, request InRequest) (InResponse, error) { +func (command *Command) Run(destinationDir string, request Request) (Response, error) { if ok, message := request.Source.IsValid(); !ok { - return InResponse{}, errors.New(message) + return Response{}, errors.New(message) } err := os.MkdirAll(destinationDir, 0755) if err != nil { - return InResponse{}, err + return Response{}, err } var remotePath string @@ -56,14 +56,14 @@ func (command *InCommand) Run(destinationDir string, request InRequest) (InRespo if request.Source.Regexp != "" { if request.Version.Path == "" { - return InResponse{}, ErrMissingPath + return Response{}, ErrMissingPath } remotePath = request.Version.Path extraction, ok := versions.Extract(remotePath, request.Source.Regexp) if !ok { - return InResponse{}, fmt.Errorf("regex does not match provided version: %#v", request.Version) + return Response{}, fmt.Errorf("regex does not match provided version: %#v", request.Version) } versionNumber = extraction.VersionNumber @@ -82,36 +82,36 @@ func (command *InCommand) Run(destinationDir string, request InRequest) (InRespo ) if err != nil { - return InResponse{}, err + return Response{}, err } if request.Params.Unpack { destinationPath := filepath.Join(destinationDir, path.Base(remotePath)) mime := archiveMimetype(destinationPath) if mime == "" { - return InResponse{}, fmt.Errorf("not an archive: %s", destinationPath) + return Response{}, fmt.Errorf("not an archive: %s", destinationPath) } err = extractArchive(mime, destinationPath) if err != nil { - return InResponse{}, err + return Response{}, err } } url := command.urlProvider.GetURL(request, remotePath) if err = command.writeURLFile(destinationDir, url); err != nil { - return InResponse{}, err + return Response{}, err } err = command.writeVersionFile(versionNumber, destinationDir) if err != nil { - return InResponse{}, err + return Response{}, err } metadata := command.metadata(remotePath, request.Source.Private, url) if versionID == "" { - return InResponse{ + return Response{ Version: s3resource.Version{ Path: remotePath, }, @@ -119,7 +119,7 @@ func (command *InCommand) Run(destinationDir string, request InRequest) (InRespo }, nil } - return InResponse{ + return Response{ Version: s3resource.Version{ VersionID: versionID, }, @@ -127,15 +127,15 @@ func (command *InCommand) Run(destinationDir string, request InRequest) (InRespo }, nil } -func (command *InCommand) writeURLFile(destDir string, url string) error { +func (command *Command) writeURLFile(destDir string, url string) error { return ioutil.WriteFile(filepath.Join(destDir, "url"), []byte(url), 0644) } -func (command *InCommand) writeVersionFile(versionNumber string, destDir string) error { +func (command *Command) writeVersionFile(versionNumber string, destDir string) error { return ioutil.WriteFile(filepath.Join(destDir, "version"), []byte(versionNumber), 0644) } -func (command *InCommand) downloadFile(bucketName string, remotePath string, versionID string, destinationDir string, destinationFile string) error { +func (command *Command) downloadFile(bucketName string, remotePath string, versionID string, destinationDir string, destinationFile string) error { localPath := filepath.Join(destinationDir, destinationFile) return command.s3client.DownloadFile( @@ -146,7 +146,7 @@ func (command *InCommand) downloadFile(bucketName string, remotePath string, ver ) } -func (command *InCommand) metadata(remotePath string, private bool, url string) []s3resource.MetadataPair { +func (command *Command) metadata(remotePath string, private bool, url string) []s3resource.MetadataPair { remoteFilename := filepath.Base(remotePath) metadata := []s3resource.MetadataPair{ diff --git a/in/in_command_test.go b/in/in_command_test.go index 2b75b838..161e6354 100644 --- a/in/in_command_test.go +++ b/in/in_command_test.go @@ -26,10 +26,10 @@ var _ = Describe("In Command", func() { var ( tmpPath string destDir string - request InRequest + request Request s3client *fakes.FakeS3Client - command *InCommand + command *Command ) BeforeEach(func() { @@ -38,7 +38,7 @@ var _ = Describe("In Command", func() { Ω(err).ShouldNot(HaveOccurred()) destDir = filepath.Join(tmpPath, "destination") - request = InRequest{ + request = Request{ Source: s3resource.Source{ Bucket: "bucket-name", Regexp: "files/a-file-(.*)", @@ -49,7 +49,7 @@ var _ = Describe("In Command", func() { } s3client = &fakes.FakeS3Client{} - command = NewInCommand(s3client) + command = NewCommand(s3client) s3client.URLReturns("http://google.com") }) diff --git a/in/models.go b/in/models.go index c5ef98e9..1eebbc7b 100644 --- a/in/models.go +++ b/in/models.go @@ -2,7 +2,7 @@ package in import "github.com/concourse/s3-resource" -type InRequest struct { +type Request struct { Source s3resource.Source `json:"source"` Version s3resource.Version `json:"version"` Params Params `json:"params"` @@ -12,7 +12,7 @@ type Params struct { Unpack bool `json:"unpack"` } -type InResponse struct { +type Response struct { Version s3resource.Version `json:"version"` Metadata []s3resource.MetadataPair `json:"metadata"` } diff --git a/integration/in_test.go b/integration/in_test.go index b596e805..3decfacf 100644 --- a/integration/in_test.go +++ b/integration/in_test.go @@ -55,10 +55,10 @@ var _ = Describe("in", func() { }) Context("with a versioned_file and a regex", func() { - var inRequest in.InRequest + var inRequest in.Request BeforeEach(func() { - inRequest = in.InRequest{ + inRequest = in.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -84,12 +84,12 @@ var _ = Describe("in", func() { }) Context("when the given version only has a path", func() { - var inRequest in.InRequest + var inRequest in.Request var directoryPrefix string BeforeEach(func() { directoryPrefix = "in-request-files" - inRequest = in.InRequest{ + inRequest = in.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -133,11 +133,11 @@ var _ = Describe("in", func() { It("downloads the file", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response in.InResponse + var response in.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(in.InResponse{ + Ω(response).Should(Equal(in.Response{ Version: s3resource.Version{ Path: "in-request-files/some-file-2", }, @@ -171,13 +171,13 @@ var _ = Describe("in", func() { }) Context("when the given version has a versionID and path", func() { - var inRequest in.InRequest + var inRequest in.Request var directoryPrefix string var expectedVersion string BeforeEach(func() { directoryPrefix = "in-request-files-versioned" - inRequest = in.InRequest{ + inRequest = in.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -226,10 +226,10 @@ var _ = Describe("in", func() { It("downloads the file", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response in.InResponse + var response in.Response err := json.NewDecoder(reader).Decode(&response) - Ω(response).Should(Equal(in.InResponse{ + Ω(response).Should(Equal(in.Response{ Version: s3resource.Version{ VersionID: expectedVersion, }, @@ -263,7 +263,7 @@ var _ = Describe("in", func() { }) Context("when cloudfront_url is set", func() { - var inRequest in.InRequest + var inRequest in.Request var directoryPrefix string BeforeEach(func() { @@ -272,7 +272,7 @@ var _ = Describe("in", func() { } directoryPrefix = "in-request-cloudfront-files" - inRequest = in.InRequest{ + inRequest = in.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -316,11 +316,11 @@ var _ = Describe("in", func() { It("downloads the file from CloudFront", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response in.InResponse + var response in.Response err := json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(in.InResponse{ + Ω(response).Should(Equal(in.Response{ Version: s3resource.Version{ Path: "in-request-cloudfront-files/some-file-2", }, @@ -349,10 +349,10 @@ var _ = Describe("in", func() { }) Context("when cloudfront_url is set but has too few dots", func() { - var inRequest in.InRequest + var inRequest in.Request BeforeEach(func() { - inRequest = in.InRequest{ + inRequest = in.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, From ced1eb23f44a2afa36576a1dedc8f85072aee175 Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Mon, 5 Feb 2018 22:09:49 +0900 Subject: [PATCH 3/4] remove package name from func name's prefix around out --- cmd/out/main.go | 8 ++++---- integration/out_test.go | 36 ++++++++++++++++++------------------ out/models.go | 4 ++-- out/out_command.go | 28 ++++++++++++++-------------- out/out_command_test.go | 8 ++++---- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/cmd/out/main.go b/cmd/out/main.go index cb025d7b..6101c6aa 100644 --- a/cmd/out/main.go +++ b/cmd/out/main.go @@ -14,7 +14,7 @@ func main() { os.Exit(1) } - var request out.OutRequest + var request out.Request inputRequest(&request) sourceDir := os.Args[1] @@ -35,7 +35,7 @@ func main() { request.Source.UseV2Signing, ) - command := out.NewOutCommand(os.Stderr, client) + command := out.NewCommand(os.Stderr, client) response, err := command.Run(sourceDir, request) if err != nil { s3resource.Fatal("running command", err) @@ -44,13 +44,13 @@ func main() { outputResponse(response) } -func inputRequest(request *out.OutRequest) { +func inputRequest(request *out.Request) { if err := json.NewDecoder(os.Stdin).Decode(request); err != nil { s3resource.Fatal("reading request from stdin", err) } } -func outputResponse(response out.OutResponse) { +func outputResponse(response out.Response) { if err := json.NewEncoder(os.Stdout).Encode(response); err != nil { s3resource.Fatal("writing response to stdout", err) } diff --git a/integration/out_test.go b/integration/out_test.go index 5a1d9d4a..3431f9bb 100644 --- a/integration/out_test.go +++ b/integration/out_test.go @@ -57,10 +57,10 @@ var _ = Describe("out", func() { }) Context("with a versioned_file and a regex", func() { - var outRequest out.OutRequest + var outRequest out.Request BeforeEach(func() { - outRequest = out.OutRequest{ + outRequest = out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -88,7 +88,7 @@ var _ = Describe("out", func() { BeforeEach(func() { ioutil.WriteFile(filepath.Join(sourceDir, "content-typed-file"), []byte("text only"), 0755) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -131,7 +131,7 @@ var _ = Describe("out", func() { BeforeEach(func() { ioutil.WriteFile(filepath.Join(sourceDir, "uncontent-typed-file"), []byte("text only"), 0755) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -172,7 +172,7 @@ var _ = Describe("out", func() { Context("with a file glob and from", func() { BeforeEach(func() { - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -218,7 +218,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "glob-file-to-upload"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -251,11 +251,11 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Buffer().Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ Path: filepath.Join(directoryPrefix, "glob-file-to-upload"), }, @@ -297,7 +297,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -324,11 +324,11 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ Path: filepath.Join(directoryPrefix, "file-to-upload"), }, @@ -351,7 +351,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload-local"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -401,7 +401,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload-local"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -429,14 +429,14 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) versions, err := s3client.BucketFileVersions(versionedBucketName, filepath.Join(directoryPrefix, "file-to-upload")) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ VersionID: versions[0], }, @@ -459,7 +459,7 @@ var _ = Describe("out", func() { err := ioutil.WriteFile(filepath.Join(sourceDir, "file-to-upload"), []byte("contents"), 0755) Ω(err).ShouldNot(HaveOccurred()) - outRequest := out.OutRequest{ + outRequest := out.Request{ Source: s3resource.Source{ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, @@ -486,14 +486,14 @@ var _ = Describe("out", func() { reader := bytes.NewBuffer(session.Out.Contents()) - var response out.OutResponse + var response out.Response err = json.NewDecoder(reader).Decode(&response) Ω(err).ShouldNot(HaveOccurred()) versions, err := s3client.BucketFileVersions(versionedBucketName, filepath.Join(directoryPrefix, "file-to-upload")) Ω(err).ShouldNot(HaveOccurred()) - Ω(response).Should(Equal(out.OutResponse{ + Ω(response).Should(Equal(out.Response{ Version: s3resource.Version{ Path: filepath.Join(directoryPrefix, "file-to-upload"), }, diff --git a/out/models.go b/out/models.go index 72e4a273..29240aca 100644 --- a/out/models.go +++ b/out/models.go @@ -4,7 +4,7 @@ import ( "github.com/concourse/s3-resource" ) -type OutRequest struct { +type Request struct { Source s3resource.Source `json:"source"` Params Params `json:"params"` } @@ -17,7 +17,7 @@ type Params struct { ContentType string `json:"content_type"` } -type OutResponse struct { +type Response struct { Version s3resource.Version `json:"version"` Metadata []s3resource.MetadataPair `json:"metadata"` } diff --git a/out/out_command.go b/out/out_command.go index 5177597f..765b50f0 100644 --- a/out/out_command.go +++ b/out/out_command.go @@ -22,33 +22,33 @@ func init() { ErrorColor.EnableColor() } -type OutCommand struct { +type Command struct { stderr io.Writer s3client s3resource.S3Client } -func NewOutCommand(stderr io.Writer, s3client s3resource.S3Client) *OutCommand { - return &OutCommand{ +func NewCommand(stderr io.Writer, s3client s3resource.S3Client) *Command { + return &Command{ stderr: stderr, s3client: s3client, } } -func (command *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, error) { +func (command *Command) Run(sourceDir string, request Request) (Response, error) { if request.Params.From != "" || request.Params.To != "" { command.printDeprecationWarning() } if ok, message := request.Source.IsValid(); !ok { - return OutResponse{}, errors.New(message) + return Response{}, errors.New(message) } if request.Params.File != "" && request.Params.From != "" { - return OutResponse{}, errors.New("contains both file and from") + return Response{}, errors.New("contains both file and from") } localPath, err := command.match(request.Params, sourceDir) if err != nil { - return OutResponse{}, err + return Response{}, err } remotePath := command.remotePath(request, localPath, sourceDir) @@ -72,14 +72,14 @@ func (command *OutCommand) Run(sourceDir string, request OutRequest) (OutRespons options, ) if err != nil { - return OutResponse{}, err + return Response{}, err } version := s3resource.Version{} if request.Source.VersionedFile != "" { if versionID == "" { - return OutResponse{}, ErrObjectVersioningNotEnabled + return Response{}, ErrObjectVersioningNotEnabled } version.VersionID = versionID @@ -87,13 +87,13 @@ func (command *OutCommand) Run(sourceDir string, request OutRequest) (OutRespons version.Path = remotePath } - return OutResponse{ + return Response{ Version: version, Metadata: command.metadata(bucketName, remotePath, request.Source.Private, versionID), }, nil } -func (command *OutCommand) remotePath(request OutRequest, localPath string, sourceDir string) string { +func (command *Command) remotePath(request Request, localPath string, sourceDir string) string { if request.Source.VersionedFile != "" { return request.Source.VersionedFile } @@ -116,7 +116,7 @@ func parentDir(regexp string) string { return regexp[:strings.LastIndex(regexp, "/")+1] } -func (command *OutCommand) match(params Params, sourceDir string) (string, error) { +func (command *Command) match(params Params, sourceDir string) (string, error) { var matches []string var err error var pattern string @@ -149,7 +149,7 @@ func (command *OutCommand) match(params Params, sourceDir string) (string, error return matches[0], nil } -func (command *OutCommand) metadata(bucketName, remotePath string, private bool, versionID string) []s3resource.MetadataPair { +func (command *Command) metadata(bucketName, remotePath string, private bool, versionID string) []s3resource.MetadataPair { remoteFilename := filepath.Base(remotePath) metadata := []s3resource.MetadataPair{ @@ -169,7 +169,7 @@ func (command *OutCommand) metadata(bucketName, remotePath string, private bool, return metadata } -func (command *OutCommand) printDeprecationWarning() { +func (command *Command) printDeprecationWarning() { errorColor := ErrorColor.SprintFunc() blinkColor := BlinkingErrorColor.SprintFunc() command.stderr.Write([]byte(blinkColor("WARNING:"))) diff --git a/out/out_command_test.go b/out/out_command_test.go index 07561acf..0fdb86db 100644 --- a/out/out_command_test.go +++ b/out/out_command_test.go @@ -19,11 +19,11 @@ var _ = Describe("Out Command", func() { var ( tmpPath string sourceDir string - request out.OutRequest + request out.Request stderr *gbytes.Buffer s3client *fakes.FakeS3Client - command *out.OutCommand + command *out.Command ) BeforeEach(func() { @@ -35,7 +35,7 @@ var _ = Describe("Out Command", func() { err = os.MkdirAll(sourceDir, 0755) Ω(err).ShouldNot(HaveOccurred()) - request = out.OutRequest{ + request = out.Request{ Source: s3resource.Source{ Bucket: "bucket-name", }, @@ -43,7 +43,7 @@ var _ = Describe("Out Command", func() { s3client = &fakes.FakeS3Client{} stderr = gbytes.NewBuffer() - command = out.NewOutCommand(stderr, s3client) + command = out.NewCommand(stderr, s3client) }) AfterEach(func() { From 15130b8725ae93ebfb1709a35f54c752d2926f5e Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Mon, 19 Mar 2018 12:24:17 +0900 Subject: [PATCH 4/4] change command file name --- check/{check_command.go => command.go} | 0 check/{check_command_test.go => command_test.go} | 0 in/{in_command.go => command.go} | 0 in/{in_command_test.go => command_test.go} | 0 out/{out_command.go => command.go} | 0 out/{out_command_test.go => command_test.go} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename check/{check_command.go => command.go} (100%) rename check/{check_command_test.go => command_test.go} (100%) rename in/{in_command.go => command.go} (100%) rename in/{in_command_test.go => command_test.go} (100%) rename out/{out_command.go => command.go} (100%) rename out/{out_command_test.go => command_test.go} (100%) diff --git a/check/check_command.go b/check/command.go similarity index 100% rename from check/check_command.go rename to check/command.go diff --git a/check/check_command_test.go b/check/command_test.go similarity index 100% rename from check/check_command_test.go rename to check/command_test.go diff --git a/in/in_command.go b/in/command.go similarity index 100% rename from in/in_command.go rename to in/command.go diff --git a/in/in_command_test.go b/in/command_test.go similarity index 100% rename from in/in_command_test.go rename to in/command_test.go diff --git a/out/out_command.go b/out/command.go similarity index 100% rename from out/out_command.go rename to out/command.go diff --git a/out/out_command_test.go b/out/command_test.go similarity index 100% rename from out/out_command_test.go rename to out/command_test.go