From 9c940540647f95e747555bc9ba31583751f619d0 Mon Sep 17 00:00:00 2001 From: cappyzawa Date: Mon, 5 Feb 2018 21:43:12 +0900 Subject: [PATCH] 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], },