Skip to content

Commit

Permalink
remove package name from func name's prefix around check
Browse files Browse the repository at this point in the history
  • Loading branch information
cappyzawa committed Feb 5, 2018
1 parent 245e81b commit 9c94054
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
22 changes: 11 additions & 11 deletions check/check_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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 {
Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions check/check_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ 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() {
var err error
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",
Expand Down
4 changes: 2 additions & 2 deletions check/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions cmd/check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
var request check.CheckRequest
var request check.Request
inputRequest(&request)

awsConfig := s3resource.NewAwsConfig(
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
48 changes: 24 additions & 24 deletions integration/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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"),
},
Expand All @@ -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,
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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],
},
Expand All @@ -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,
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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"),
},
Expand Down Expand Up @@ -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"),
},
Expand All @@ -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,
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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],
},
Expand Down Expand Up @@ -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],
},
Expand Down

0 comments on commit 9c94054

Please sign in to comment.