From b98753397cdc0208f6608babc358de29b05017e5 Mon Sep 17 00:00:00 2001 From: Stephen Levine Date: Thu, 26 Oct 2017 23:12:13 -0400 Subject: [PATCH] Update forge, update dep, refactor --- .travis.yml | 2 +- Gopkg.lock | 10 +++---- cf/cmd/cmd.go | 16 +++++------ cf/cmd/export_test.go | 8 +++--- cf/cmd/mocks/config.go | 8 +++--- cf/cmd/mocks/remote_app.go | 12 ++++---- cf/cmd/pull_test.go | 5 ++-- cf/cmd/push_test.go | 3 +- cf/cmd/run.go | 19 ++++++------- cf/cmd/run_test.go | 14 +++++----- cf/cmd/stage.go | 6 ++-- cf/cmd/stage_test.go | 14 +++++----- cf/cmd/wait.go | 21 ++++++++++++++ main_test.go | 8 +++--- plugin/buildpacks.go | 2 +- plugin/plugin.go | 57 ++++++++++---------------------------- remote/service.go | 14 +++++----- remote/service_test.go | 10 +++---- ui/ui.go | 2 +- ui/ui_test.go | 8 ++---- 20 files changed, 115 insertions(+), 124 deletions(-) create mode 100644 cf/cmd/wait.go diff --git a/.travis.yml b/.travis.yml index eaaadbe..d2c71ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ go: - 1.9.x install: - set -e -- curl -fsSLo "$GOPATH/bin/dep" "https://github.com/golang/dep/releases/download/v0.3.1/dep-linux-amd64" +- curl -fsSLo "$GOPATH/bin/dep" "https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64" - chmod +x "$GOPATH/bin/dep" - curl -fsSL "https://cli.run.pivotal.io/stable?release=linux64-binary" | tar -C "$GOPATH/bin" -xz cf - bin/vendor diff --git a/Gopkg.lock b/Gopkg.lock index 36a92b5..6c7baf2 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -37,7 +37,7 @@ [[projects]] name = "github.com/cloudfoundry/bytefmt" packages = ["."] - revision = "f4415fafc5619dd75599a54a7c91fb3948ad58bd" + revision = "df625de5ac824ed098ad814bd960b4c2dc481898" [[projects]] name = "github.com/docker/distribution" @@ -146,13 +146,13 @@ [[projects]] branch = "master" name = "github.com/sclevine/forge" - packages = [".","app","engine","outlock","service","version","wait"] - revision = "e4d1cd9d0ec475f366a1472470422e658c55c4e1" + packages = [".","app","engine","fixtures","internal"] + revision = "11b46106a1c684f5b6e7643ed74b1fff75330d18" [[projects]] name = "github.com/vito/go-interact" packages = ["interact","interact/terminal"] - revision = "c5a3f51ad50e34ec101050f69383caa75082f233" + revision = "cbd56b28e8411a00fd4b7f92e8c870581558bf26" [[projects]] name = "golang.org/x/crypto" @@ -184,6 +184,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d458d632393501ca4e05651113d33b2209073108f237f3f17b0ede3924faa908" + inputs-digest = "1342b192f31bb1ff8636b788df0a7d559d4b2c717e8d6d7e8dbfd188a94fd9da" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cf/cmd/cmd.go b/cf/cmd/cmd.go index 5094c84..f3fd264 100644 --- a/cf/cmd/cmd.go +++ b/cf/cmd/cmd.go @@ -10,8 +10,8 @@ import ( "github.com/sclevine/cflocal/fs" "github.com/sclevine/cflocal/remote" "github.com/sclevine/forge" + "github.com/sclevine/forge/app" "github.com/sclevine/forge/engine" - "github.com/sclevine/forge/service" ) const LatestStack = "cloudfoundry/cflinuxfs2:latest" @@ -31,8 +31,8 @@ type RemoteApp interface { Env(name string) (*remote.AppEnv, error) SetEnv(name string, env map[string]string) error Restart(name string) error - Services(name string) (service.Services, error) - Forward(name string, services service.Services) (service.Services, *service.ForwardConfig, error) + Services(name string) (forge.Services, error) + Forward(name string, services forge.Services) (forge.Services, *forge.ForwardDetails, error) } //go:generate mockgen -package mocks -destination mocks/local_app.go github.com/sclevine/cflocal/cf/cmd LocalApp @@ -74,8 +74,8 @@ type Help interface { //go:generate mockgen -package mocks -destination mocks/config.go github.com/sclevine/cflocal/cf/cmd Config type Config interface { - Load() (*forge.LocalYML, error) - Save(localYML *forge.LocalYML) error + Load() (*app.LocalYML, error) + Save(localYML *app.LocalYML) error } func parseOptions(args []string, f func(name string, set *flag.FlagSet)) error { @@ -94,7 +94,7 @@ func parseOptions(args []string, f func(name string, set *flag.FlagSet)) error { return nil } -func getAppConfig(name string, localYML *forge.LocalYML) *forge.AppConfig { +func getAppConfig(name string, localYML *app.LocalYML) *forge.AppConfig { var app *forge.AppConfig for _, appConfig := range localYML.Applications { if appConfig.Name == name { @@ -108,8 +108,8 @@ func getAppConfig(name string, localYML *forge.LocalYML) *forge.AppConfig { return app } -func getRemoteServices(app RemoteApp, serviceApp, forwardApp string) (service.Services, *service.ForwardConfig, error) { - var services service.Services +func getRemoteServices(app RemoteApp, serviceApp, forwardApp string) (forge.Services, *forge.ForwardDetails, error) { + var services forge.Services if serviceApp == "" { serviceApp = forwardApp diff --git a/cf/cmd/export_test.go b/cf/cmd/export_test.go index 98888cd..54e64c1 100644 --- a/cf/cmd/export_test.go +++ b/cf/cmd/export_test.go @@ -12,8 +12,8 @@ import ( "github.com/sclevine/cflocal/cf/cmd/mocks" sharedmocks "github.com/sclevine/cflocal/mocks" "github.com/sclevine/forge" + "github.com/sclevine/forge/app" "github.com/sclevine/forge/engine" - "github.com/sclevine/forge/service" ) var _ = Describe("Export", func() { @@ -63,13 +63,13 @@ var _ = Describe("Export", func() { It("should export a droplet as a Docker image", func() { droplet := sharedmocks.NewMockBuffer("some-droplet") launcher := sharedmocks.NewMockBuffer("some-launcher") - localYML := &forge.LocalYML{ + localYML := &app.LocalYML{ Applications: []*forge.AppConfig{ {Name: "some-other-app"}, { Name: "some-app", Env: map[string]string{"a": "b"}, - Services: service.Services{"some": {{Name: "services"}}}, + Services: forge.Services{"some": {{Name: "services"}}}, }, }, } @@ -85,7 +85,7 @@ var _ = Describe("Export", func() { Expect(config.AppConfig).To(Equal(&forge.AppConfig{ Name: "some-app", Env: map[string]string{"a": "b"}, - Services: service.Services{"some": {{Name: "services"}}}, + Services: forge.Services{"some": {{Name: "services"}}}, })) }, ).Return("some-id", nil) diff --git a/cf/cmd/mocks/config.go b/cf/cmd/mocks/config.go index 417442d..20d4585 100644 --- a/cf/cmd/mocks/config.go +++ b/cf/cmd/mocks/config.go @@ -6,7 +6,7 @@ package mocks import ( gomock "github.com/golang/mock/gomock" - forge "github.com/sclevine/forge" + app "github.com/sclevine/forge/app" reflect "reflect" ) @@ -34,9 +34,9 @@ func (m *MockConfig) EXPECT() *MockConfigMockRecorder { } // Load mocks base method -func (m *MockConfig) Load() (*forge.LocalYML, error) { +func (m *MockConfig) Load() (*app.LocalYML, error) { ret := m.ctrl.Call(m, "Load") - ret0, _ := ret[0].(*forge.LocalYML) + ret0, _ := ret[0].(*app.LocalYML) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -47,7 +47,7 @@ func (mr *MockConfigMockRecorder) Load() *gomock.Call { } // Save mocks base method -func (m *MockConfig) Save(arg0 *forge.LocalYML) error { +func (m *MockConfig) Save(arg0 *app.LocalYML) error { ret := m.ctrl.Call(m, "Save", arg0) ret0, _ := ret[0].(error) return ret0 diff --git a/cf/cmd/mocks/remote_app.go b/cf/cmd/mocks/remote_app.go index b6eb903..437a708 100644 --- a/cf/cmd/mocks/remote_app.go +++ b/cf/cmd/mocks/remote_app.go @@ -7,7 +7,7 @@ package mocks import ( gomock "github.com/golang/mock/gomock" remote "github.com/sclevine/cflocal/remote" - service "github.com/sclevine/forge/service" + forge "github.com/sclevine/forge" io "io" reflect "reflect" ) @@ -76,10 +76,10 @@ func (mr *MockRemoteAppMockRecorder) Env(arg0 interface{}) *gomock.Call { } // Forward mocks base method -func (m *MockRemoteApp) Forward(arg0 string, arg1 service.Services) (service.Services, *service.ForwardConfig, error) { +func (m *MockRemoteApp) Forward(arg0 string, arg1 forge.Services) (forge.Services, *forge.ForwardDetails, error) { ret := m.ctrl.Call(m, "Forward", arg0, arg1) - ret0, _ := ret[0].(service.Services) - ret1, _ := ret[1].(*service.ForwardConfig) + ret0, _ := ret[0].(forge.Services) + ret1, _ := ret[1].(*forge.ForwardDetails) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } @@ -102,9 +102,9 @@ func (mr *MockRemoteAppMockRecorder) Restart(arg0 interface{}) *gomock.Call { } // Services mocks base method -func (m *MockRemoteApp) Services(arg0 string) (service.Services, error) { +func (m *MockRemoteApp) Services(arg0 string) (forge.Services, error) { ret := m.ctrl.Call(m, "Services", arg0) - ret0, _ := ret[0].(service.Services) + ret0, _ := ret[0].(forge.Services) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/cf/cmd/pull_test.go b/cf/cmd/pull_test.go index 5ee33bc..8917bfa 100644 --- a/cf/cmd/pull_test.go +++ b/cf/cmd/pull_test.go @@ -11,6 +11,7 @@ import ( sharedmocks "github.com/sclevine/cflocal/mocks" "github.com/sclevine/cflocal/remote" "github.com/sclevine/forge" + "github.com/sclevine/forge/app" ) var _ = Describe("Pull", func() { @@ -62,7 +63,7 @@ var _ = Describe("Pull", func() { Running: map[string]string{"c": "d"}, App: map[string]string{"e": "f"}, } - oldLocalYML := &forge.LocalYML{ + oldLocalYML := &app.LocalYML{ Applications: []*forge.AppConfig{ {Name: "some-other-app"}, { @@ -74,7 +75,7 @@ var _ = Describe("Pull", func() { }, }, } - newLocalYML := &forge.LocalYML{ + newLocalYML := &app.LocalYML{ Applications: []*forge.AppConfig{ {Name: "some-other-app"}, { diff --git a/cf/cmd/push_test.go b/cf/cmd/push_test.go index 083e918..fb723af 100644 --- a/cf/cmd/push_test.go +++ b/cf/cmd/push_test.go @@ -13,6 +13,7 @@ import ( "github.com/sclevine/cflocal/cf/cmd/mocks" sharedmocks "github.com/sclevine/cflocal/mocks" "github.com/sclevine/forge" + "github.com/sclevine/forge/app" ) var _ = Describe("Push", func() { @@ -58,7 +59,7 @@ var _ = Describe("Push", func() { Describe("#Run", func() { It("should replace an app's droplet and env vars, then restart it", func() { droplet := sharedmocks.NewMockBuffer("some-droplet") - localYML := &forge.LocalYML{ + localYML := &app.LocalYML{ Applications: []*forge.AppConfig{ {Name: "some-other-app"}, { diff --git a/cf/cmd/run.go b/cf/cmd/run.go index 62462e9..4dd1302 100644 --- a/cf/cmd/run.go +++ b/cf/cmd/run.go @@ -14,7 +14,6 @@ import ( "github.com/docker/docker/api/types" "github.com/sclevine/forge" "github.com/sclevine/forge/engine" - "github.com/sclevine/forge/wait" ) type Run struct { @@ -109,17 +108,17 @@ func (r *Run) Run(args []string) error { return err } defer sshpass.Close() - waiter, waiterDone := wait.New(5 * time.Second) + waiter, waiterDone := newWaiter(5 * time.Second) defer waiterDone() health, done, id, err := r.Forwarder.Forward(&forge.ForwardConfig{ - AppName: appConfig.Name, - Stack: LatestStack, - SSHPass: sshpass, - Color: color.GreenString, - ForwardConfig: forwardConfig, - HostIP: netConfig.HostIP, - HostPort: netConfig.HostPort, - Wait: waiter, + AppName: appConfig.Name, + Stack: LatestStack, + SSHPass: sshpass, + Color: color.GreenString, + Details: forwardConfig, + HostIP: netConfig.HostIP, + HostPort: netConfig.HostPort, + Wait: waiter, }) if err != nil { return err diff --git a/cf/cmd/run_test.go b/cf/cmd/run_test.go index 236531b..470b64b 100644 --- a/cf/cmd/run_test.go +++ b/cf/cmd/run_test.go @@ -15,8 +15,8 @@ import ( "github.com/sclevine/cflocal/cf/cmd/mocks" sharedmocks "github.com/sclevine/cflocal/mocks" "github.com/sclevine/forge" + "github.com/sclevine/forge/app" "github.com/sclevine/forge/engine" - "github.com/sclevine/forge/service" ) var _ = Describe("Run", func() { @@ -73,23 +73,23 @@ var _ = Describe("Run", func() { droplet := sharedmocks.NewMockBuffer("some-droplet") launcher := sharedmocks.NewMockBuffer("some-launcher") sshpass := sharedmocks.NewMockBuffer("some-sshpass") - services := service.Services{"some": {{Name: "services"}}} - forwardedServices := service.Services{"some": {{Name: "forwarded-services"}}} + services := forge.Services{"some": {{Name: "services"}}} + forwardedServices := forge.Services{"some": {{Name: "forwarded-services"}}} restart := make(<-chan time.Time) watchDone := make(chan struct{}) health := make(chan string, 3) forwardDone, forwardDoneCalls := sharedmocks.NewMockFunc() - forwardConfig := &service.ForwardConfig{ + forwardConfig := &forge.ForwardDetails{ Host: "some-ssh-host", } - localYML := &forge.LocalYML{ + localYML := &app.LocalYML{ Applications: []*forge.AppConfig{ {Name: "some-other-app"}, { Name: "some-app", Env: map[string]string{"a": "b"}, - Services: service.Services{"some": {{Name: "overwritten-services"}}}, + Services: forge.Services{"some": {{Name: "overwritten-services"}}}, }, }, } @@ -110,7 +110,7 @@ var _ = Describe("Run", func() { Expect(config.AppName).To(Equal("some-app")) Expect(config.Stack).To(Equal(LatestStack)) Expect(config.Color("some-text")).To(Equal(color.GreenString("some-text"))) - Expect(config.ForwardConfig).To(Equal(forwardConfig)) + Expect(config.Details).To(Equal(forwardConfig)) Expect(config.HostIP).To(Equal("0.0.0.0")) Expect(config.HostPort).To(Equal("3000")) Eventually(config.Wait).Should(Receive()) diff --git a/cf/cmd/stage.go b/cf/cmd/stage.go index 2e7cdd2..16e4f83 100644 --- a/cf/cmd/stage.go +++ b/cf/cmd/stage.go @@ -4,9 +4,9 @@ import ( "crypto/md5" "flag" "fmt" + "io" "github.com/fatih/color" - "github.com/sclevine/forge" "github.com/sclevine/forge/engine" ) @@ -15,7 +15,7 @@ type Stage struct { UI UI Stager Stager RemoteApp RemoteApp - LocalApp LocalApp + TarApp func(string) (io.ReadCloser, error) FS FS Help Help Config Config @@ -51,7 +51,7 @@ func (s *Stage) Run(args []string) error { return err } - appTar, err := s.LocalApp.Tar(options.app) + appTar, err := s.TarApp(options.app) if err != nil { return err } diff --git a/cf/cmd/stage_test.go b/cf/cmd/stage_test.go index 0af7d5a..fb567fa 100644 --- a/cf/cmd/stage_test.go +++ b/cf/cmd/stage_test.go @@ -15,8 +15,8 @@ import ( "github.com/sclevine/cflocal/cf/cmd/mocks" sharedmocks "github.com/sclevine/cflocal/mocks" "github.com/sclevine/forge" + "github.com/sclevine/forge/app" "github.com/sclevine/forge/engine" - "github.com/sclevine/forge/service" ) var _ = Describe("Stage", func() { @@ -45,7 +45,7 @@ var _ = Describe("Stage", func() { UI: mockUI, Stager: mockStager, RemoteApp: mockRemoteApp, - LocalApp: mockLocalApp, + TarApp: mockLocalApp.Tar, FS: mockFS, Help: mockHelp, Config: mockConfig, @@ -74,13 +74,13 @@ var _ = Describe("Stage", func() { droplet := sharedmocks.NewMockBuffer("some-droplet") dropletFile := sharedmocks.NewMockBuffer("") - services := service.Services{"some": {{Name: "services"}}} - forwardedServices := service.Services{"some": {{Name: "forwarded-services"}}} - forwardConfig := &service.ForwardConfig{ + services := forge.Services{"some": {{Name: "services"}}} + forwardedServices := forge.Services{"some": {{Name: "forwarded-services"}}} + forwardConfig := &forge.ForwardDetails{ Host: "some-ssh-host", } - localYML := &forge.LocalYML{ + localYML := &app.LocalYML{ Applications: []*forge.AppConfig{ { Name: "some-other-app", @@ -93,7 +93,7 @@ var _ = Describe("Stage", func() { "some-other-buildpack-two", }, Env: map[string]string{"a": "b"}, - Services: service.Services{"some": {{Name: "overwritten-services"}}}, + Services: forge.Services{"some": {{Name: "overwritten-services"}}}, }, }, } diff --git a/cf/cmd/wait.go b/cf/cmd/wait.go new file mode 100644 index 0000000..f0ed085 --- /dev/null +++ b/cf/cmd/wait.go @@ -0,0 +1,21 @@ +package cmd + +import "time" + +func newWaiter(d time.Duration) (waiter <-chan time.Time, done func()) { + wait := make(chan time.Time) + stop := make(chan struct{}) + go func() { + for { + select { + case wait <- time.Now(): + time.Sleep(d) + case <-stop: + return + } + } + }() + return wait, func() { + close(stop) + } +} diff --git a/main_test.go b/main_test.go index 84c15c9..1387ac8 100644 --- a/main_test.go +++ b/main_test.go @@ -254,7 +254,7 @@ var _ = Describe("CF Local", func() { cfSession, err := gexec.Start(cfPushCmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) - Eventually(cfSession, "1m").Should(gexec.Exit(0)) + Eventually(cfSession, "2m").Should(gexec.Exit(0)) pushCmd := exec.Command("cf", "local", "push", "some-name") pushCmd.Dir = filepath.Join(tempDir, "go-app") @@ -317,7 +317,7 @@ var _ = Describe("CF Local", func() { cfSession, err := gexec.Start(cfPushCmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) - Eventually(cfSession, "1m").Should(gexec.Exit(0)) + Eventually(cfSession, "2m").Should(gexec.Exit(0)) pushCmd := exec.Command("cf", "local", "push", "some-name") pushCmd.Dir = filepath.Join(tempDir, "local-app") @@ -340,7 +340,7 @@ var _ = Describe("CF Local", func() { cfPushCmd.Dir = filepath.Join(tempDir, "go-app") cfSession, err := gexec.Start(cfPushCmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) - Eventually(cfSession, "1m").Should(gexec.Exit(0)) + Eventually(cfSession, "2m").Should(gexec.Exit(0)) }) By("creating", func() { @@ -362,7 +362,7 @@ var _ = Describe("CF Local", func() { cfStart := exec.Command("cf", "start", "remote-app") cfSession, err := gexec.Start(cfStart, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) - Eventually(cfSession, "1m").Should(gexec.Exit(0)) + Eventually(cfSession, "2m").Should(gexec.Exit(0)) }) By("staging", func() { diff --git a/plugin/buildpacks.go b/plugin/buildpacks.go index c93f282..5e2fd2d 100644 --- a/plugin/buildpacks.go +++ b/plugin/buildpacks.go @@ -3,7 +3,7 @@ package plugin import "github.com/sclevine/forge" // TODO: merge the version URLs into a single JSON file with download URLs -var SystemBuildpacks forge.SystemBuildpacks = []forge.Buildpack{ +var SystemBuildpacks forge.Buildpacks = []forge.Buildpack{ { Name: "staticfile_buildpack", URL: "https://github.com/cloudfoundry/staticfile-buildpack/releases/download/v{{.}}/staticfile-buildpack-v{{.}}.zip", diff --git a/plugin/plugin.go b/plugin/plugin.go index da5f166..6cf655c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -15,15 +15,13 @@ import ( "github.com/fatih/color" goversion "github.com/hashicorp/go-version" "github.com/kardianos/osext" + "github.com/sclevine/forge" + "github.com/sclevine/forge/app" "github.com/sclevine/cflocal/cf" "github.com/sclevine/cflocal/cf/cmd" "github.com/sclevine/cflocal/fs" "github.com/sclevine/cflocal/remote" - "github.com/sclevine/forge" - "github.com/sclevine/forge/app" - "github.com/sclevine/forge/engine" - "github.com/sclevine/forge/version" ) type Plugin struct { @@ -77,51 +75,26 @@ func (p *Plugin) Run(cliConnection cfplugin.CliConnection, args []string) { ExpectContinueTimeout: 1 * time.Second, }, } + stager := forge.NewStager(client, &http.Client{}, p.Exit) + stager.ImageTag = "cflocal" + stager.SystemBuildpacks = SystemBuildpacks + stager.Logs = color.Output + stager.Loader = p.UI - dockerEngine := &forge.DockerEngine{ - Docker: client, - } - dockerEngineWithExit := &forge.DockerEngine{ - Docker: client, - Exit: p.Exit, - } - imageWithExit := &engine.Image{ - Docker: client, - Exit: p.Exit, - } - versioner := &version.URL{ - Client: &http.Client{}, - } - stager := &forge.Stager{ - DiegoVersion: "1.26.1", - GoVersion: "1.8.3", - ImageTag: "cflocal", - SystemBuildpacks: SystemBuildpacks, - Logs: color.Output, - Loader: p.UI, - Engine: dockerEngineWithExit, - Image: imageWithExit, - Versioner: versioner, - } + runner := forge.NewRunner(client, p.Exit) + runner.Logs = color.Output + runner.Loader = p.UI + + forwarder := forge.NewForwarder(client) + forwarder.Logs = color.Output - runner := &forge.Runner{ - Logs: color.Output, - Loader: p.UI, - Engine: dockerEngineWithExit, - Image: imageWithExit, - } - forwarder := &forge.Forwarder{ - Logs: color.Output, - Engine: dockerEngine, - } remoteApp := &remote.App{ CLI: cliConnection, UI: p.UI, HTTP: ccHTTPClient, } - localApp := &app.App{} sysFS := &fs.FS{} - config := &forge.Config{ + config := &app.Config{ Path: "./local.yml", } help := &Help{ @@ -168,7 +141,7 @@ func (p *Plugin) Run(cliConnection cfplugin.CliConnection, args []string) { UI: p.UI, Stager: stager, RemoteApp: remoteApp, - LocalApp: localApp, + TarApp: app.Tar, FS: sysFS, Help: help, Config: config, diff --git a/remote/service.go b/remote/service.go index e1e3673..5767745 100644 --- a/remote/service.go +++ b/remote/service.go @@ -10,12 +10,12 @@ import ( "strconv" "strings" - "github.com/sclevine/forge/service" + "github.com/sclevine/forge" ) const firstForwardedServicePort uint = 40000 -func (a *App) Services(name string) (service.Services, error) { +func (a *App) Services(name string) (forge.Services, error) { appEnvJSON, _, err := a.get(name, "/env") if err != nil { return nil, err @@ -23,7 +23,7 @@ func (a *App) Services(name string) (service.Services, error) { defer appEnvJSON.Close() var env struct { SystemEnvJSON struct { - VCAPServices service.Services `json:"VCAP_SERVICES"` + VCAPServices forge.Services `json:"VCAP_SERVICES"` } `json:"system_env_json"` } if err := json.NewDecoder(appEnvJSON).Decode(&env); err != nil { @@ -32,9 +32,9 @@ func (a *App) Services(name string) (service.Services, error) { return env.SystemEnvJSON.VCAPServices, nil } -func (a *App) Forward(name string, svcs service.Services) (service.Services, *service.ForwardConfig, error) { +func (a *App) Forward(name string, svcs forge.Services) (forge.Services, *forge.ForwardDetails, error) { var err error - config := &service.ForwardConfig{} + config := &forge.ForwardDetails{} if config.Host, config.Port, err = a.sshEndpoint(); err != nil { return nil, nil, err @@ -62,7 +62,7 @@ func (a *App) Forward(name string, svcs service.Services) (service.Services, *se for i, svc := range svcs[svcType] { name := fmt.Sprintf("%s:%s[%d]", svc.Name, svcType, i) if address := forward(svc.Credentials, "localhost", forwardedPort); address != "" { - config.Forwards = append(config.Forwards, service.Forward{ + config.Forwards = append(config.Forwards, forge.Forward{ Name: name, From: strconv.FormatUint(uint64(forwardedPort), 10), To: address, @@ -79,7 +79,7 @@ func (a *App) Forward(name string, svcs service.Services) (service.Services, *se return svcs, config, nil } -func serviceTypes(s service.Services) (types []string) { +func serviceTypes(s forge.Services) (types []string) { for t := range s { types = append(types, t) } diff --git a/remote/service_test.go b/remote/service_test.go index 054d598..ae8d4d5 100644 --- a/remote/service_test.go +++ b/remote/service_test.go @@ -12,7 +12,7 @@ import ( "github.com/sclevine/cflocal/mocks" . "github.com/sclevine/cflocal/remote" "github.com/sclevine/cflocal/testutil" - "github.com/sclevine/forge/service" + "github.com/sclevine/forge" ) var _ = Describe("App - Service", func() { @@ -54,7 +54,7 @@ var _ = Describe("App - Service", func() { } } }`) - Expect(app.Services("some-name")).To(Equal(service.Services{ + Expect(app.Services("some-name")).To(Equal(forge.Services{ "some-type": { { Name: "some-name", @@ -82,7 +82,7 @@ var _ = Describe("App - Service", func() { mockCLI.EXPECT().GetApp("some-name").Return(plugin_models.GetAppModel{Guid: "some-guid"}, nil), ) - services, config, err := app.Forward("some-name", service.Services{ + services, config, err := app.Forward("some-name", forge.Services{ "common": { { Name: "some-name-0", @@ -188,7 +188,7 @@ var _ = Describe("App - Service", func() { }, }) Expect(err).NotTo(HaveOccurred()) - Expect(services).To(Equal(service.Services{ + Expect(services).To(Equal(forge.Services{ "common": { { Name: "some-name-0", @@ -297,7 +297,7 @@ var _ = Describe("App - Service", func() { Expect(config.Host).To(Equal("some-ssh-host")) Expect(config.Port).To(Equal("1000")) Expect(config.User).To(Equal("cf:some-guid/0")) - Expect(config.Forwards).To(Equal([]service.Forward{ + Expect(config.Forwards).To(Equal([]forge.Forward{ { Name: "some-name-0:common[0]", From: "40000", diff --git a/ui/ui.go b/ui/ui.go index fb0567a..e2db7a3 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -89,7 +89,7 @@ func (u *UI) Loading(message string, progress <-chan engine.Progress) (err error fmt.Fprintf(u.Out, "\r%s\r", strings.Repeat(" ", max(loadLen, spinLen))) return err } - switch status, pErr := p.Status(), p.Err(); { + switch status, pErr := p.Status(); { case pErr != nil: err = pErr case status == "N/A": diff --git a/ui/ui_test.go b/ui/ui_test.go index 53c5aa6..889350c 100644 --- a/ui/ui_test.go +++ b/ui/ui_test.go @@ -115,10 +115,6 @@ type mockProgress struct { err error } -func (m mockProgress) Err() error { - return m.err -} - -func (m mockProgress) Status() string { - return "some-progress" +func (m mockProgress) Status() (string, error) { + return "some-progress", m.err }