Skip to content

Commit

Permalink
remove package name from func name's prefix around out
Browse files Browse the repository at this point in the history
  • Loading branch information
cappyzawa committed Feb 5, 2018
1 parent 2b0a6fe commit ced1eb2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions cmd/out/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
os.Exit(1)
}

var request out.OutRequest
var request out.Request
inputRequest(&request)

sourceDir := os.Args[1]
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
36 changes: 18 additions & 18 deletions integration/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
},
Expand Down Expand Up @@ -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,
Expand All @@ -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"),
},
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
},
Expand All @@ -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,
Expand All @@ -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"),
},
Expand Down
4 changes: 2 additions & 2 deletions out/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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"`
}
28 changes: 14 additions & 14 deletions out/out_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -72,28 +72,28 @@ 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
} else {
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
}
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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:")))
Expand Down
8 changes: 4 additions & 4 deletions out/out_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -35,15 +35,15 @@ 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",
},
}

s3client = &fakes.FakeS3Client{}
stderr = gbytes.NewBuffer()
command = out.NewOutCommand(stderr, s3client)
command = out.NewCommand(stderr, s3client)
})

AfterEach(func() {
Expand Down

0 comments on commit ced1eb2

Please sign in to comment.