当前位置: 首页>>代码示例>>Golang>>正文


Golang FakeCliConnection.CliCommandWithoutTerminalOutputReturns方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/cli/plugin/fakes.FakeCliConnection.CliCommandWithoutTerminalOutputReturns方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeCliConnection.CliCommandWithoutTerminalOutputReturns方法的具体用法?Golang FakeCliConnection.CliCommandWithoutTerminalOutputReturns怎么用?Golang FakeCliConnection.CliCommandWithoutTerminalOutputReturns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/cli/plugin/fakes.FakeCliConnection的用法示例。


在下文中一共展示了FakeCliConnection.CliCommandWithoutTerminalOutputReturns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestGetApps

func TestGetApps(t *testing.T) {
	conn := new(fakes.FakeCliConnection)

	content, fileReadErr := readFile("test-data/apps.json")

	if fileReadErr != nil {
		panic("Failed to read file: " + fileReadErr.Error())
	}

	conn.CliCommandWithoutTerminalOutputReturns(content, nil)

	cmd := new(DiegoMigrationCmd)

	space := Space{AppsUrl: "/fake-apps-url"}

	apps, err := cmd.getApps(conn, space)

	if err != nil {
		t.Errorf("getApps Returned an error: %v", err.Error())
	}

	if len(apps.Resources) == 0 {
		t.Error("expected at least one result from getApps")
	}

	for _, appResource := range apps.Resources {
		if appResource.Entity.Name == "" {
			t.Error("Name was null on SpaceResource.Entity")
		}
	}
}
开发者ID:pivotalservices,项目名称:diego-migration-plugin,代码行数:31,代码来源:diegomigration_test.go

示例2: TestGetOrgs

func TestGetOrgs(t *testing.T) {
	conn := new(fakes.FakeCliConnection)

	content, fileReadErr := readFile("test-data/orgs.json")

	if fileReadErr != nil {
		panic("Failed to read file: " + fileReadErr.Error())
	}

	conn.CliCommandWithoutTerminalOutputReturns(content, nil)

	cmd := new(DiegoMigrationCmd)

	orgs, err := cmd.getOrgs(conn)

	if err != nil {
		t.Errorf("getOrgs Returned an error: %v", err.Error())
	}

	if len(orgs.Resources) == 0 {
		t.Error("expected at least one result from getOrgs")
	}

	for _, orgResource := range orgs.Resources {
		if orgResource.Entity.SpacesUrl == "" {
			t.Error("SpacesURL was null on OrgResource.Entity")
		}

		if orgResource.Entity.Name == "" {
			t.Error("Name was null on OrgResource.Entity")
		}
	}
}
开发者ID:pivotalservices,项目名称:diego-migration-plugin,代码行数:33,代码来源:diegomigration_test.go

示例3:

	"github.com/cloudfoundry/cli/plugin/fakes"
	"io/ioutil"
)

var _ = Describe("API", func() {
	Describe("StartedApps", func() {
		var cliConnection *fakes.FakeCliConnection

		BeforeEach(func() {
			cliConnection = &fakes.FakeCliConnection{}
		})

		It("Lists app starts apps", func() {
			getAppsJsonPage, _ := ioutil.ReadFile("fixtures/apps.json")
			cliConnection.CliCommandWithoutTerminalOutputReturns([]string{string(getAppsJsonPage)}, nil)

			api := NewCliCcApi(cliConnection)
			apps, _ := api.StartedApps()

			Expect(len(apps)).To(Equal(45))
		})
	})

	Describe("AppStats", func() {
		var cliConnection *fakes.FakeCliConnection

		BeforeEach(func() {
			cliConnection = &fakes.FakeCliConnection{}
		})
开发者ID:davidehringer,项目名称:cf-ip-query-plugin,代码行数:29,代码来源:api_test.go

示例4:

			_, err := appenv.GetEnvs(fakeCliConnection, []string{"app_name"})
			Expect(err).To(MatchError("You must login first!"))
		})
	})

	Context("when no app name is supplied", func() {
		It("returns an error message", func() {
			_, err := appenv.GetEnvs(fakeCliConnection, []string{})
			Expect(err).To(MatchError("You must specify an app name"))
		})
	})

	Context("when getting vcap_services", func() {
		appname := "APP_NAME"
		BeforeEach(func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{"hi"}, nil)
			appenv.GetEnvs(fakeCliConnection, []string{"something", appname})
		})

		It("calls cli", func() {
			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).
				To(Not(BeZero()))
		})

		It("requests the correct app envs", func() {
			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).
				To(Equal([]string{"env", appname}))
		})
	})

	Context("parsing json app environment data", func() {
开发者ID:Samze,项目名称:appenvs,代码行数:31,代码来源:appenv_test.go

示例5:

var _ = Describe("Info", func() {
	var (
		fakeCliConnection *fakes.FakeCliConnection
		infoFactory       info.InfoFactory
	)

	BeforeEach(func() {
		fakeCliConnection = &fakes.FakeCliConnection{}
		infoFactory = info.NewInfoFactory(fakeCliConnection)
	})

	Describe("Get", func() {
		var expectedJson string

		JustBeforeEach(func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{expectedJson}, nil)
		})

		Context("when retrieving /v2/info is successful", func() {
			BeforeEach(func() {
				expectedJson = `{
					"app_ssh_endpoint": "ssh.example.com:1234",
					"app_ssh_host_key_fingerprint": "00:11:22:33:44:55:66:77:88"
				}`

				fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{expectedJson}, nil)
			})

			It("returns a populated Info model", func() {
				model, err := infoFactory.Get()
				Expect(err).NotTo(HaveOccurred())
开发者ID:sykesm,项目名称:diego-ssh,代码行数:31,代码来源:info_test.go

示例6:

	var fakeCliConnection *fakes.FakeCliConnection

	BeforeEach(func() {
		fakeCliConnection = &fakes.FakeCliConnection{}
		api = &APIHelper{}
	})

	Describe("Get orgs", func() {
		var orgsJSON []string

		BeforeEach(func() {
			orgsJSON = slurp("test-data/orgs.json")
		})

		It("should return two orgs", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns(orgsJSON, nil)
			orgs, _ := api.GetOrgs(fakeCliConnection)
			Expect(len(orgs)).To(Equal(2))
		})

		It("does something intellegent when cf curl fails", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns(
				nil, errors.New("bad things"))
			_, err := api.GetOrgs(fakeCliConnection)
			Expect(err).ToNot(BeNil())
		})

		It("populates the url", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns(orgsJSON, nil)
			orgs, _ := api.GetOrgs(fakeCliConnection)
			org := orgs[0]
开发者ID:ECSTeam,项目名称:usagereport-plugin,代码行数:31,代码来源:apihelper_test.go

示例7:

		BeforeEach(func() {
			fakeCliConnection = &fakes.FakeCliConnection{}
			callCopyEnvCommandPlugin = &CopyEnv{}
		})

		It("Extract Application Name From Command Line Args", func() {
			name, err := callCopyEnvCommandPlugin.ExtractAppName([]string{"copyenv"})
			Ω(err).Should(MatchError("missing application name"))

			name, err = callCopyEnvCommandPlugin.ExtractAppName([]string{"copyenv", "APP_NAME"})
			Ω(err).ShouldNot(HaveOccurred())
			Ω(name).Should(Equal("APP_NAME"))
		})

		It("Retrieve Application Environment Variables From Name", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{"SOME", "OUTPUT", "COMMAND"}, nil)
			output, err := callCopyEnvCommandPlugin.RetrieveAppNameEnv(fakeCliConnection, "APP_NAME")
			Ω(err).ShouldNot(HaveOccurred())
			Ω(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).Should(Equal(1))
			Ω(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).Should(Equal([]string{"env", "APP_NAME"}))
			Ω(output).Should(Equal([]string{"SOME", "OUTPUT", "COMMAND"}))
		})

		It("Return Service Credentials From Appplication Environment", func() {
			_, err := callCopyEnvCommandPlugin.ExtractCredentialsJSON("VCAP_SERVICES", []string{""})
			Ω(err).Should(MatchError("missing service credentials for application"))

			service_creds := []string{"{\"VCAP_SERVICES\":{\"service\": [ { \"credentials\": {} } ]}}"}
			b, err := callCopyEnvCommandPlugin.ExtractCredentialsJSON("VCAP_SERVICES", service_creds)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(string(b[:])).Should(Equal("{\"service\":[{\"credentials\":{}}]}"))
开发者ID:Samze,项目名称:copyenv,代码行数:31,代码来源:copyenv_test.go

示例8:

					curler = func(cli plugin.CliConnection, result interface{}, args ...string) error {
						return errors.New("not good")
					}
				})

				It("returns an error", func() {
					_, err := af.Get("app1")
					Expect(err).To(MatchError("Failed to acquire app1 info"))
				})
			})
		})

		Context("when the app does not exist", func() {
			BeforeEach(func() {
				fakeCliConnection.CliCommandWithoutTerminalOutputReturns(
					[]string{"FAILED", "App app1 is not found"},
					errors.New("Error executing cli core command"),
				)
			})

			It("returns 'App not found' error", func() {
				_, err := af.Get("app1")
				Expect(err).To(MatchError("App app1 is not found"))

				Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1))
				args := fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)
				Expect(args).To(ConsistOf("app", "app1", "--guid"))
			})
		})
	})
})
开发者ID:sykesm,项目名称:diego-ssh,代码行数:31,代码来源:app_test.go

示例9:

var _ = Describe("Curl", func() {
	var fakeCliConnection *fakes.FakeCliConnection

	BeforeEach(func() {
		fakeCliConnection = &fakes.FakeCliConnection{}
	})

	Context("with a valid response", func() {
		type MyStruct struct {
			SomeString string
		}

		BeforeEach(func() {
			input := []string{"{", `"somestring": "foo"`, "}"}
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns(input, nil)
		})

		It("unmarshals a successful response", func() {
			var result MyStruct
			err := Curl(fakeCliConnection, &result, "a", "b", "c")
			Expect(err).NotTo(HaveOccurred())
			Expect(result.SomeString).To(Equal("foo"))

			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1))
			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).To(Equal([]string{"curl", "a", "b", "c"}))
		})

		It("succeeds with no response object", func() {
			err := Curl(fakeCliConnection, nil, "a", "b", "c")
			Expect(err).NotTo(HaveOccurred())
开发者ID:sykesm,项目名称:diego-ssh,代码行数:30,代码来源:curl_test.go

示例10:

		It("returns an error when the uaa certificate is not valid and certificate validation is enabled", func() {
			fakeCliConnection.IsSSLDisabledReturns(false, nil)

			_, err := credFactory.AuthorizationCode()
			Expect(err).To(HaveOccurred())

			urlErr, ok := err.(*url.Error)
			Expect(ok).To(BeTrue())
			Expect(urlErr.Err).To(MatchError(ContainSubstring("signed by unknown authority")))

			Expect(fakeUAA.ReceivedRequests()).To(HaveLen(0))
		})

		It("returns the error from the cli when refreshing the access token fails", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{}, errors.New("woops"))

			_, err := credFactory.AuthorizationCode()
			Expect(err).To(MatchError("woops"))

			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1))
			Expect(fakeCliConnection.AccessTokenCallCount()).To(Equal(0))
		})

		It("returns the error from the cli when getting the access token fails", func() {
			fakeCliConnection.AccessTokenReturns("", errors.New("woops"))

			_, err := credFactory.AuthorizationCode()
			Expect(err).To(MatchError("woops"))

			Expect(fakeCliConnection.AccessTokenCallCount()).To(Equal(1))
开发者ID:krishicks,项目名称:diego-ssh,代码行数:30,代码来源:credential_test.go

示例11:

			if scanner.Err() != nil {
				Fail("Failed to read lines from file")
			}

			if 0 == len(v2apps) {
				Fail("you didn't read anything in")
			}
		})

		AfterEach(func() {
			v2apps = nil
		})

		Describe("cf cli results validation", func() {
			It("returns an error when there is no output", func() {
				fakeCliConnection.CliCommandWithoutTerminalOutputReturns(nil, nil)
				appsJSON, err := Curl(fakeCliConnection, "/v2/apps")
				Expect(err).ToNot(BeNil())
				Expect(appsJSON).To(BeNil())
			})

			It("returns an error with zero length output", func() {

				fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{""}, nil)
				appsJSON, err := Curl(fakeCliConnection, "/v2/apps")
				Expect(err).ToNot(BeNil())
				Expect(appsJSON).To(BeNil())
			})

			It("should call the path specified", func() {
				fakeCliConnection.CliCommandWithoutTerminalOutputReturns(v2apps, nil)
开发者ID:krujos,项目名称:cfcurl,代码行数:31,代码来源:cfcurl_test.go

示例12:

	. "github.com/onsi/gomega"
)

var _ = Describe("Scaleover", func() {
	var scaleoverCmdPlugin *ScaleoverCmd
	var fakeCliConnection *fakes.FakeCliConnection

	Describe("getAppStatus", func() {

		BeforeEach(func() {
			fakeCliConnection = &fakes.FakeCliConnection{}
			scaleoverCmdPlugin = &ScaleoverCmd{}
		})

		It("should Fail Without App 1", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{"FAILED", "App app1 not found"}, nil)
			var err error
			_, err = scaleoverCmdPlugin.getAppStatus(fakeCliConnection, "app1")
			Expect(err.Error()).To(Equal("App app1 not found"))
		})

		It("should Fail Without App 2", func() {
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{"FAILED", "App app2 not found"}, nil)
			var err error
			_, err = scaleoverCmdPlugin.getAppStatus(fakeCliConnection, "app2")
			Expect(err.Error()).To(Equal("App app2 not found"))
		})

		It("should not start a stopped target with 1 instance", func() {
			cfAppOutput := []string{"requested state: stopped", "instances: 0/1"}
			fakeCliConnection.CliCommandWithoutTerminalOutputReturns(cfAppOutput, nil)
开发者ID:TomG713,项目名称:scaleover-plugin,代码行数:31,代码来源:scaleover_test.go

示例13:

            "filename": "staticfile_buildpack-cached-v1.2.0.zip"
         }
      }
   ]
}`

var _ = Describe("BuildpackRepo", func() {
	Describe("ListAll", func() {
		var cliConnection *fakes.FakeCliConnection

		BeforeEach(func() {
			cliConnection = &fakes.FakeCliConnection{}
		})

		It("outputs a slice of all admin buildpacks", func() {
			cliConnection.CliCommandWithoutTerminalOutputReturns([]string{getBuildpacksJson}, nil)

			repo := NewCliBuildpackRepository(cliConnection)
			buildpacks, _ := repo.ListBuildpacks()

			Expect(buildpacks[0].Name).To(Equal("java"))
			Expect(buildpacks[0].Position).To(Equal(1))
			Expect(buildpacks[0].Enabled).To(Equal(true))
			Expect(buildpacks[0].Locked).To(Equal(false))
			Expect(buildpacks[0].Filename).To(Equal("java-buildpack-offline-v3.0.zip"))

			Expect(len(buildpacks)).To(Equal(10))
		})
	})
})
开发者ID:davidehringer,项目名称:cf-buildpack-management-plugin,代码行数:30,代码来源:buildpack-repo_test.go

示例14:

		fakeCliConnection = &fakes.FakeCliConnection{}
		credFactory = credential.NewCredentialFactory(fakeCliConnection)
	})

	Describe("Get", func() {
		var expectedResponse []string

		Context("when retrieving /v2/info is successful", func() {
			BeforeEach(func() {
				expectedResponse = []string{
					"Getting OAuth token\n",
					"OK\n",
					"bearer lives_in_a_man_cave",
				}

				fakeCliConnection.CliCommandWithoutTerminalOutputReturns(expectedResponse, nil)
			})

			It("returns a populated Info model", func() {
				cred, err := credFactory.Get()
				Expect(err).NotTo(HaveOccurred())

				Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1))
				Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).To(ConsistOf("oauth-token"))

				Expect(cred.Token).To(Equal("bearer lives_in_a_man_cave"))
			})
		})

		Context("when getting the oauth-token fails", func() {
			BeforeEach(func() {
开发者ID:sykesm,项目名称:diego-ssh,代码行数:31,代码来源:credential_test.go

示例15:

	"github.com/cloudfoundry-incubator/diego-enabler/diego_support"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("DiegoSupport", func() {
	var (
		fakeCliConnection *fakes.FakeCliConnection
		diegoSupport      *diego_support.DiegoSupport
	)

	BeforeEach(func() {
		fakeCliConnection = &fakes.FakeCliConnection{}
		fakeCliConnection.CliCommandWithoutTerminalOutputReturns([]string{""}, nil)
		diegoSupport = diego_support.NewDiegoSupport(fakeCliConnection)
	})

	Describe("SetDiegoFlag", func() {
		It("invokes CliCommandWithoutTerminalOutput()", func() {
			diegoSupport.SetDiegoFlag("123", false)

			Ω(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1))
		})

		It("calls cli core command 'curl'", func() {
			diegoSupport.SetDiegoFlag("123", false)

			Ω(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)[0]).To(Equal("curl"))
		})
开发者ID:krishicks,项目名称:Diego-Enabler,代码行数:30,代码来源:diego_support_test.go


注:本文中的github.com/cloudfoundry/cli/plugin/fakes.FakeCliConnection.CliCommandWithoutTerminalOutputReturns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。