Skip to content

Commit

Permalink
Using go generate for mock generation. Adding docker-username to dock…
Browse files Browse the repository at this point in the history
…er push.
  • Loading branch information
Lars Gohr committed Nov 20, 2017
1 parent bc61c8f commit 3471369
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 22 deletions.
9 changes: 7 additions & 2 deletions out/cloud_foundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"os/exec"
)

//go:generate counterfeiter . PAAS
type PAAS interface {
Login(api string, username string, password string, insecure bool) error
Target(organization string, space string) error
PushApp(manifest string, path string, currentAppName string) error
PushApp(manifest string, path string, currentAppName string, dockerUser string) error
}

type CloudFoundry struct{}
Expand All @@ -35,7 +36,7 @@ func (cf *CloudFoundry) Target(organization string, space string) error {
return cf.cf("target", "-o", organization, "-s", space).Run()
}

func (cf *CloudFoundry) PushApp(manifest string, path string, currentAppName string) error {
func (cf *CloudFoundry) PushApp(manifest string, path string, currentAppName string, dockerUser string) error {
args := []string{}

if currentAppName == "" {
Expand All @@ -44,6 +45,10 @@ func (cf *CloudFoundry) PushApp(manifest string, path string, currentAppName str
args = append(args, "zero-downtime-push", currentAppName, "-f", manifest)
}

if dockerUser != "" {
args = append(args, "--docker-username", dockerUser)
}

if path != "" {
stat, err := os.Stat(path)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions out/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (command *Command) Run(request Request) (Response, error) {
request.Params.ManifestPath,
request.Params.Path,
request.Params.CurrentAppName,
request.Params.DockerUsername,
)
if err != nil {
return Response{}, err
Expand Down
37 changes: 32 additions & 5 deletions out/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (

"github.com/concourse/cf-resource"
"github.com/concourse/cf-resource/out"
"github.com/concourse/cf-resource/out/fakes"
"github.com/concourse/cf-resource/out/outfakes"
"io"
"io/ioutil"
)

var _ = Describe("Out Command", func() {
var (
cloudFoundry *fakes.FakePAAS
cloudFoundry *outfakes.FakePAAS
request out.Request
command *out.Command
)

BeforeEach(func() {
cloudFoundry = &fakes.FakePAAS{}
cloudFoundry = &outfakes.FakePAAS{}
command = out.NewCommand(cloudFoundry)

request = out.Request{
Expand Down Expand Up @@ -78,10 +78,11 @@ var _ = Describe("Out Command", func() {
By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))

manifest, path, currentAppName := cloudFoundry.PushAppArgsForCall(0)
manifest, path, currentAppName, dockerUser := cloudFoundry.PushAppArgsForCall(0)
Expect(manifest).To(Equal("assets/manifest.yml"))
Expect(path).To(Equal(""))
Expect(currentAppName).To(Equal(""))
Expect(dockerUser).To(Equal(""))
})

Describe("handling any errors", func() {
Expand Down Expand Up @@ -219,10 +220,36 @@ var _ = Describe("Out Command", func() {
By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))

_, _, currentAppName := cloudFoundry.PushAppArgsForCall(0)
_, _, currentAppName, _ := cloudFoundry.PushAppArgsForCall(0)
Expect(currentAppName).To(Equal("cool-app-name"))
})

It("lets people define a user for connecting to a docker registry", func() {
request = out.Request{
Source: resource.Source{
API: "https://api.run.pivotal.io",
Username: "awesome@example.com",
Password: "hunter2",
Organization: "secret",
Space: "volcano-base",
},
Params: out.Params{
ManifestPath: "a/path/to/a/manifest.yml",
CurrentAppName: "cool-app-name",
DockerUsername: "DOCKER_USER",
},
}

_, err := command.Run(request)
Expect(err).NotTo(HaveOccurred())

By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))

_, _, _, dockerUser := cloudFoundry.PushAppArgsForCall(0)
Expect(dockerUser).To(Equal("DOCKER_USER"))
})

Context("using a docker registry which requires authentication", func() {

var savedVar string
Expand Down
34 changes: 34 additions & 0 deletions out/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,38 @@ var _ = Describe("Out", func() {
})
})
})

Context("when accessing a protected docker registry", func() {
BeforeEach(func() {
request.Params.DockerUsername = "DOCKER_USERNAME"
request.Params.DockerPassword = "DOCKER_PASSWORD"
})

It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))

var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())

Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))

// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth awesome@example.com hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf zero-downtime-push awesome-app -f %s --docker-username %s",
filepath.Join(tmpDir, "project/manifest.yml"),
request.Params.DockerUsername,
))
Expect(session.Err).To(gbytes.Say("CF_DOCKER_PASSWORD=DOCKER_PASSWORD"))
})
})
})
1 change: 1 addition & 0 deletions out/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Params struct {
Path string `json:"path"`
CurrentAppName string `json:"current_app_name"`
EnvironmentVariables map[string]string `json:"environment_variables"`
DockerUsername string `json:"docker_username"`
DockerPassword string `json:"docker_password"`
}

Expand Down
120 changes: 105 additions & 15 deletions out/fakes/fake_paas.go → out/outfakes/fake_paas.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3471369

Please sign in to comment.