示例#1
0
文件: help_test.go 项目: nttlabs/cli
func createCommandFactory() command_factory.Factory {
	fakeUI := &testterm.FakeUI{}
	configRepo := testconfig.NewRepository()
	pluginConfig := &testPluginConfig.FakePluginConfiguration{}

	manifestRepo := manifest.NewManifestDiskRepository()
	apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(configRepo, fakeUI),
		"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI),
		"uaa":              net.NewUAAGateway(configRepo, fakeUI),
	})

	return command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig)
}
示例#2
0
文件: main.go 项目: nttlabs/cli
func setupDependencies() (deps *cliDependencies) {
	deps = new(cliDependencies)

	deps.teePrinter = terminal.NewTeePrinter()

	deps.termUI = terminal.NewUI(os.Stdin, deps.teePrinter)

	deps.manifestRepo = manifest.NewManifestDiskRepository()

	errorHandler := func(err error) {
		if err != nil {
			deps.termUI.Failed(fmt.Sprintf("Config error: %s", err))
		}
	}
	deps.configRepo = core_config.NewRepositoryFromFilepath(config_helpers.DefaultFilePath(), errorHandler)
	deps.pluginConfig = plugin_config.NewPluginConfig(errorHandler)

	i18n.T = i18n.Init(deps.configRepo)

	terminal.UserAskedForColors = deps.configRepo.ColorEnabled()
	terminal.InitColorSupport()

	if os.Getenv("CF_TRACE") != "" {
		trace.Logger = trace.NewLogger(os.Getenv("CF_TRACE"))
	} else {
		trace.Logger = trace.NewLogger(deps.configRepo.Trace())
	}

	deps.gateways = map[string]net.Gateway{
		"auth":             net.NewUAAGateway(deps.configRepo, deps.termUI),
		"cloud-controller": net.NewCloudControllerGateway(deps.configRepo, time.Now, deps.termUI),
		"uaa":              net.NewUAAGateway(deps.configRepo, deps.termUI),
	}
	deps.apiRepoLocator = api.NewRepositoryLocator(deps.configRepo, deps.gateways)

	return
}
示例#3
0
文件: context.go 项目: nttlabs/cli
func findCommand(cmdName string) (cmd cli.Command) {
	fakeUI := &testterm.FakeUI{}
	configRepo := testconfig.NewRepository()
	pluginConfig := &testPluginConfig.FakePluginConfiguration{}
	manifestRepo := manifest.NewManifestDiskRepository()
	apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(configRepo, fakeUI),
		"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI),
		"uaa":              net.NewUAAGateway(configRepo, fakeUI),
	})

	cmdFactory := command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig)
	requirementsFactory := &testreq.FakeReqFactory{}
	cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, fakeUI)
	myApp := app.NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)

	for _, cmd := range myApp.Commands {
		if cmd.Name == cmdName {
			return cmd
		}
	}
	panic(fmt.Sprintf("command %s does not exist", cmdName))
	return
}
示例#4
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("factory", func() {
	var (
		factory Factory
	)

	BeforeEach(func() {
		fakeUI := &testterm.FakeUI{}
		config := testconfig.NewRepository()
		manifestRepo := manifest.NewManifestDiskRepository()
		pluginConfig := &testPluginConfig.FakePluginConfiguration{}
		repoLocator := api.NewRepositoryLocator(config, map[string]net.Gateway{
			"auth":             net.NewUAAGateway(config, fakeUI),
			"cloud-controller": net.NewCloudControllerGateway(config, time.Now, fakeUI),
			"uaa":              net.NewUAAGateway(config, fakeUI),
		})

		factory = NewFactory(fakeUI, config, manifestRepo, repoLocator, pluginConfig)
	})

	It("provides the metadata for its commands", func() {
		commands := factory.CommandMetadatas()

		suffixesToIgnore := []string{
			"i18n_init.go", // ignore all i18n initializers
			"_test.go",     // ignore test files
			".test",        // ignore generated .test (temporary files)
			"#",            // emacs autosave files
示例#5
0
文件: users_test.go 项目: nttlabs/cli
)

var _ = Describe("User Repository", func() {
	var (
		ccServer   *httptest.Server
		ccHandler  *testnet.TestHandler
		uaaServer  *httptest.Server
		uaaHandler *testnet.TestHandler
		repo       UserRepository
		config     core_config.ReadWriter
	)

	BeforeEach(func() {
		config = testconfig.NewRepositoryWithDefaults()
		ccGateway := net.NewCloudControllerGateway((config), time.Now, &testterm.FakeUI{})
		uaaGateway := net.NewUAAGateway(config, &testterm.FakeUI{})
		repo = NewCloudControllerUserRepository(config, uaaGateway, ccGateway)
	})

	AfterEach(func() {
		if uaaServer != nil {
			uaaServer.Close()
		}
		if ccServer != nil {
			ccServer.Close()
		}
	})

	setupCCServer := func(requests ...testnet.TestRequest) {
		ccServer, ccHandler = testnet.NewServer(requests)
		config.SetApiEndpoint(ccServer.URL)
示例#6
0
文件: app_test.go 项目: nttlabs/cli
}

var _ = Describe("App", func() {
	var (
		app       *cli.App
		cmdRunner *FakeRunner
	)

	JustBeforeEach(func() {
		ui := &testterm.FakeUI{}
		config := testconfig.NewRepository()
		pluginConfig := &testPluginConfig.FakePluginConfiguration{}
		manifestRepo := &testmanifest.FakeManifestRepository{}

		repoLocator := api.NewRepositoryLocator(config, map[string]net.Gateway{
			"auth":             net.NewUAAGateway(config, ui),
			"cloud-controller": net.NewCloudControllerGateway(config, time.Now, &testterm.FakeUI{}),
			"uaa":              net.NewUAAGateway(config, ui),
		})

		cmdFactory := command_factory.NewFactory(ui, config, manifestRepo, repoLocator, pluginConfig)
		cmdRunner = &FakeRunner{cmdFactory: cmdFactory}
		app = NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)
	})

	Describe("trace file integration", func() {
		var (
			output *bytes.Buffer
		)

		BeforeEach(func() {