本文整理汇总了Golang中github.com/cloudfoundry-incubator/lattice/ltc/config/target_verifier.TargetVerifier.VerifyTarget方法的典型用法代码示例。如果您正苦于以下问题:Golang TargetVerifier.VerifyTarget方法的具体用法?Golang TargetVerifier.VerifyTarget怎么用?Golang TargetVerifier.VerifyTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/lattice/ltc/config/target_verifier.TargetVerifier
的用法示例。
在下文中一共展示了TargetVerifier.VerifyTarget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MakeCliApp
func MakeCliApp(
diegoVersion string,
latticeVersion string,
ltcConfigRoot string,
exitHandler exit_handler.ExitHandler,
config *config.Config,
logger lager.Logger,
receptorClientCreator receptor_client.Creator,
targetVerifier target_verifier.TargetVerifier,
cliStdout io.Writer,
) *cli.App {
config.Load()
app := cli.NewApp()
app.Name = AppName
app.Author = latticeCliAuthor
app.Version = defaultVersion(diegoVersion, latticeVersion)
app.Usage = LtcUsage
app.Email = "[email protected]"
ui := terminal.NewUI(os.Stdin, cliStdout, password_reader.NewPasswordReader(exitHandler))
app.Writer = ui
app.Before = func(context *cli.Context) error {
args := context.Args()
command := app.Command(args.First())
if command == nil {
return nil
}
if _, ok := nonTargetVerifiedCommandNames[command.Name]; ok || len(args) == 0 {
return nil
}
if receptorUp, authorized, err := targetVerifier.VerifyTarget(config.Receptor()); !receptorUp {
ui.SayLine(fmt.Sprintf("Error connecting to the receptor. Make sure your lattice target is set, and that lattice is up and running.\n\tUnderlying error: %s", err.Error()))
return err
} else if !authorized {
ui.SayLine("Could not authenticate with the receptor. Please run ltc target with the correct credentials.")
return errors.New("Could not authenticate with the receptor.")
}
return nil
}
app.Action = defaultAction
app.CommandNotFound = func(c *cli.Context, command string) {
ui.SayLine(fmt.Sprintf(unknownCommand, command))
exitHandler.Exit(1)
}
app.Commands = cliCommands(ltcConfigRoot, exitHandler, config, logger, receptorClientCreator, targetVerifier, ui)
return app
}
示例2:
Describe("VerifyTarget", func() {
var (
fakeReceptorClient *fake_receptor.FakeClient
fakeReceptorClientCreator *fake_receptor_client_creator.FakeCreator
targetVerifier target_verifier.TargetVerifier
)
BeforeEach(func() {
fakeReceptorClient = &fake_receptor.FakeClient{}
fakeReceptorClientCreator = &fake_receptor_client_creator.FakeCreator{}
fakeReceptorClientCreator.CreateReceptorClientReturns(fakeReceptorClient)
targetVerifier = target_verifier.New(fakeReceptorClientCreator)
})
It("returns up=true, auth=true if the receptor does not return an error", func() {
up, auth, err := targetVerifier.VerifyTarget("http://receptor.mylattice.com")
Expect(err).NotTo(HaveOccurred())
Expect(up).To(BeTrue())
Expect(auth).To(BeTrue())
Expect(fakeReceptorClientCreator.CreateReceptorClientCallCount()).To(Equal(1))
Expect(fakeReceptorClientCreator.CreateReceptorClientArgsForCall(0)).To(Equal("http://receptor.mylattice.com"))
})
It("returns up=true, auth=false if the receptor returns an authorization error", func() {
fakeReceptorClient.DesiredLRPsReturns([]receptor.DesiredLRPResponse{}, receptor.Error{
Type: receptor.Unauthorized,
Message: "Go home. You're not welcome here.",
})
up, auth, err := targetVerifier.VerifyTarget("http://receptor.mylattice.com")
Expect(err).NotTo(HaveOccurred())