func (s *versionManager) SyncLTC(ltcPath string, arch string, config *config_package.Config) error {
	response, err := http.DefaultClient.Get(fmt.Sprintf("%s/v1/sync/%s/ltc", config.Receptor(), arch))
	if err != nil {
		return fmt.Errorf("failed to connect to receptor: %s", err.Error())
	}
	if response.StatusCode != 200 {
		return fmt.Errorf("failed to download ltc: %s", response.Status)
	}

	tmpFile, err := s.fileSwapper.GetTempFile()
	if err != nil {
		return fmt.Errorf("failed to open temp file: %s", err.Error())
	}
	defer tmpFile.Close()

	_, err = io.Copy(tmpFile, response.Body)
	if err != nil {
		return fmt.Errorf("failed to write to temp ltc: %s", err.Error())
	}

	err = s.fileSwapper.SwapTempFile(ltcPath, tmpFile.Name())
	if err != nil {
		return fmt.Errorf("failed to swap ltc: %s", err.Error())
	}

	return nil
}
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 = "*****@*****.**"

	ui := terminal.NewUI(os.Stdin, cliStdout, terminal.NewPasswordReader())
	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
		}

		for _, arg := range args {
			if arg == "-h" || arg == "--help" {
				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))
			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, latticeVersion)
	return app
}
func (v BlobStoreVerifier) Verify(config *config_package.Config) (authorized bool, err error) {
	switch config.ActiveBlobStore() {
	case config_package.DAVBlobStore:
		return v.DAVBlobStoreVerifier.Verify(config)
	case config_package.S3BlobStore:
		return v.S3BlobStoreVerifier.Verify(config)
	}

	panic("unknown blob store type")
}
func New(config *config_package.Config) BlobStore {
	switch config.ActiveBlobStore() {
	case config_package.DAVBlobStore:
		return dav_blob_store.New(config.BlobStore())
	case config_package.S3BlobStore:
		return s3_blob_store.New(config.S3BlobStore())
	}

	return dav_blob_store.New(config.BlobStore())
}
func (Verifier) Verify(config *config_package.Config) (authorized bool, err error) {
	blobStoreURL := url.URL{
		Scheme: "http",
		Host:   fmt.Sprintf("%s:%s", config.BlobStore().Host, config.BlobStore().Port),
		User:   url.UserPassword(config.BlobStore().Username, config.BlobStore().Password),
	}

	baseURL := &url.URL{
		Scheme: blobStoreURL.Scheme,
		Host:   blobStoreURL.Host,
		User:   blobStoreURL.User,
		Path:   "/blobs/",
	}

	req, err := http.NewRequest("PROPFIND", baseURL.String(), nil)
	if err != nil {
		return false, err
	}

	req.Header.Add("Depth", "1")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return false, err
	}

	defer resp.Body.Close()

	return resp.StatusCode == 207, err
}
func (v Verifier) Verify(config *config_package.Config) (authorized bool, err error) {
	blobStoreConfig := config.S3BlobStore()
	client := s3.New(session.New(&aws.Config{
		Credentials:      credentials.NewStaticCredentials(blobStoreConfig.AccessKey, blobStoreConfig.SecretKey, ""),
		Region:           aws.String(blobStoreConfig.Region),
		S3ForcePathStyle: aws.Bool(true),
	}))
	if v.Endpoint != "" {
		client.Endpoint = v.Endpoint
	}
	_, err = client.ListObjects(&s3.ListObjectsInput{
		Bucket: aws.String(blobStoreConfig.BucketName),
	})
	if err != nil {
		if awsErr, ok := err.(awserr.RequestFailure); ok && awsErr.StatusCode() == 403 {
			return false, nil
		}

		return false, err
	}
	return true, nil
}
Beispiel #7
0
func (*AppDialer) Dial(appName string, instanceIndex int, config *config_package.Config) (Client, error) {
	diegoSSHUser := fmt.Sprintf("diego:%s/%d", appName, instanceIndex)
	address := fmt.Sprintf("%s:2222", config.Target())

	client, err := sshapi.New(diegoSSHUser, config.Username(), config.Password(), address)
	if err != nil {
		return nil, err
	}

	return client, nil
}
	"github.com/cloudfoundry-incubator/ltc/app_examiner/fake_app_examiner"
	config_package "github.com/cloudfoundry-incubator/ltc/config"
	"github.com/cloudfoundry-incubator/ltc/exit_handler/exit_codes"
	"github.com/cloudfoundry-incubator/ltc/exit_handler/fake_exit_handler"
	"github.com/cloudfoundry-incubator/ltc/ssh/command_factory"
	"github.com/cloudfoundry-incubator/ltc/ssh/command_factory/mocks"
	"github.com/cloudfoundry-incubator/ltc/terminal"
	"github.com/cloudfoundry-incubator/ltc/test_helpers"
	"github.com/codegangsta/cli"
)

var _ = Describe("SSH CommandFactory", func() {
	var (
		config          *config_package.Config
		outputBuffer    *gbytes.Buffer
		terminalUI      terminal.UI
		fakeExitHandler *fake_exit_handler.FakeExitHandler
		fakeAppExaminer *fake_app_examiner.FakeAppExaminer
		fakeSSH         *mocks.FakeSSH
	)

	BeforeEach(func() {
		config = config_package.New(nil)
		config.SetTarget("lattice.xip.io")

		outputBuffer = gbytes.NewBuffer()
		terminalUI = terminal.NewUI(nil, outputBuffer, nil)
		fakeExitHandler = &fake_exit_handler.FakeExitHandler{}
		fakeAppExaminer = &fake_app_examiner.FakeAppExaminer{}
		fakeSSH = &mocks.FakeSSH{}
	})
var _ = Describe("BlobStore", func() {
	const responseBody401 = `<?xml version="1.0" encoding="iso-8859-1"?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
		 <head>
		  <title>401 - Unauthorized</title>
		 </head>
		 <body>
		  <h1>401 - Unauthorized</h1>
		 </body>
		</html>`

	var (
		verifier               dav_blob_store.Verifier
		config                 *config_package.Config
		fakeServer             *ghttp.Server
		serverHost, serverPort string
	)

	BeforeEach(func() {
		config = config_package.New(nil)

		fakeServer = ghttp.NewServer()
		fakeServerURL, err := url.Parse(fakeServer.URL())
		Expect(err).NotTo(HaveOccurred())
		serverHost, serverPort, err = net.SplitHostPort(fakeServerURL.Host)
		Expect(err).NotTo(HaveOccurred())

		verifier = dav_blob_store.Verifier{}
	})
func cliCommands(ltcConfigRoot string, exitHandler exit_handler.ExitHandler, config *config.Config, logger lager.Logger, receptorClientCreator receptor_client.Creator, targetVerifier target_verifier.TargetVerifier, ui terminal.UI, latticeVersion string) []cli.Command {
	receptorClient := receptorClientCreator.CreateReceptorClient(config.Receptor())
	noaaConsumer := noaa.NewConsumer(LoggregatorUrl(config.Loggregator()), nil, nil)
	appRunner := app_runner.New(receptorClient, config.Target(), &keygen_package.KeyGenerator{RandReader: rand.Reader})

	clock := clock.NewClock()

	logReader := logs.NewLogReader(noaaConsumer)
	tailedLogsOutputter := console_tailed_logs_outputter.NewConsoleTailedLogsOutputter(ui, logReader)

	taskExaminer := task_examiner.New(receptorClient)
	taskExaminerCommandFactory := task_examiner_command_factory.NewTaskExaminerCommandFactory(taskExaminer, ui, exitHandler)

	taskRunner := task_runner.New(receptorClient, taskExaminer, clock)
	taskRunnerCommandFactory := task_runner_command_factory.NewTaskRunnerCommandFactory(taskRunner, ui, exitHandler)

	appExaminer := app_examiner.New(receptorClient, app_examiner.NewNoaaConsumer(noaaConsumer))
	graphicalVisualizer := graphical.NewGraphicalVisualizer(appExaminer)
	dockerTerminal := &app_examiner_command_factory.DockerTerminal{}
	appExaminerCommandFactory := app_examiner_command_factory.NewAppExaminerCommandFactory(appExaminer, ui, dockerTerminal, clock, exitHandler, graphicalVisualizer, taskExaminer, config.Target())

	appRunnerCommandFactoryConfig := app_runner_command_factory.AppRunnerCommandFactoryConfig{
		AppRunner:           appRunner,
		AppExaminer:         appExaminer,
		UI:                  ui,
		Domain:              config.Target(),
		Env:                 os.Environ(),
		Clock:               clock,
		Logger:              logger,
		TailedLogsOutputter: tailedLogsOutputter,
		ExitHandler:         exitHandler,
	}

	appRunnerCommandFactory := app_runner_command_factory.NewAppRunnerCommandFactory(appRunnerCommandFactoryConfig)

	dockerRunnerCommandFactoryConfig := docker_runner_command_factory.DockerRunnerCommandFactoryConfig{
		AppRunner:             appRunner,
		AppExaminer:           appExaminer,
		UI:                    ui,
		Domain:                config.Target(),
		Env:                   os.Environ(),
		Clock:                 clock,
		Logger:                logger,
		ExitHandler:           exitHandler,
		TailedLogsOutputter:   tailedLogsOutputter,
		DockerMetadataFetcher: docker_metadata_fetcher.New(docker_metadata_fetcher.NewDockerSessionFactory()),
	}
	dockerRunnerCommandFactory := docker_runner_command_factory.NewDockerRunnerCommandFactory(dockerRunnerCommandFactoryConfig)

	logsCommandFactory := logs_command_factory.NewLogsCommandFactory(appExaminer, taskExaminer, ui, tailedLogsOutputter, exitHandler)

	clusterTestRunner := cluster_test.NewClusterTestRunner(config, ltcConfigRoot)
	clusterTestCommandFactory := cluster_test_command_factory.NewClusterTestCommandFactory(clusterTestRunner)

	blobStore := blob_store.New(config)
	blobStoreVerifier := blob_store.BlobStoreVerifier{
		DAVBlobStoreVerifier: dav_blob_store.Verifier{},
		S3BlobStoreVerifier:  s3_blob_store.Verifier{},
	}

	httpProxyConfReader := &droplet_runner.HTTPProxyConfReader{
		URL: fmt.Sprintf("http://%s:8444/proxyconf.json", config.Target()),
	}
	dropletRunner := droplet_runner.New(appRunner, taskRunner, config, blobStore, appExaminer, httpProxyConfReader)
	cfIgnore := cf_ignore.New()
	zipper := &zipper_package.DropletArtifactZipper{}
	dropletRunnerCommandFactory := droplet_runner_command_factory.NewDropletRunnerCommandFactory(*appRunnerCommandFactory, blobStoreVerifier, taskExaminer, dropletRunner, cfIgnore, zipper, config)

	versionManager := version.NewVersionManager(receptorClientCreator, &version.AppFileSwapper{}, defaultLatticeVersion(latticeVersion))
	configCommandFactory := config_command_factory.NewConfigCommandFactory(config, ui, targetVerifier, blobStoreVerifier, exitHandler, versionManager)

	sshCommandFactory := ssh_command_factory.NewSSHCommandFactory(config, ui, exitHandler, appExaminer, ssh.New(exitHandler))

	ltcPath, _ := osext.Executable()
	versionCommandFactory := version_command_factory.NewVersionCommandFactory(config, ui, exitHandler, runtime.GOOS, ltcPath, versionManager)

	helpCommand := cli.Command{
		Name:        "help",
		Aliases:     []string{"h"},
		Usage:       "Shows a list of commands or help for one command",
		Description: "ltc help",
		Action:      defaultAction,
	}

	return []cli.Command{
		appExaminerCommandFactory.MakeCellsCommand(),
		dockerRunnerCommandFactory.MakeCreateAppCommand(),
		appRunnerCommandFactory.MakeSubmitLrpCommand(),
		logsCommandFactory.MakeDebugLogsCommand(),
		appExaminerCommandFactory.MakeListAppCommand(),
		logsCommandFactory.MakeLogsCommand(),
		appRunnerCommandFactory.MakeRemoveAppCommand(),
		appRunnerCommandFactory.MakeScaleAppCommand(),
		appExaminerCommandFactory.MakeStatusCommand(),
		taskRunnerCommandFactory.MakeSubmitTaskCommand(),
		configCommandFactory.MakeTargetCommand(),
		taskExaminerCommandFactory.MakeTaskCommand(),
		taskRunnerCommandFactory.MakeDeleteTaskCommand(),
		taskRunnerCommandFactory.MakeCancelTaskCommand(),
		clusterTestCommandFactory.MakeClusterTestCommand(),
		appRunnerCommandFactory.MakeUpdateCommand(),
		appExaminerCommandFactory.MakeVisualizeCommand(),
		dropletRunnerCommandFactory.MakeBuildDropletCommand(),
		dropletRunnerCommandFactory.MakeListDropletsCommand(),
		dropletRunnerCommandFactory.MakeLaunchDropletCommand(),
		dropletRunnerCommandFactory.MakeRemoveDropletCommand(),
		dropletRunnerCommandFactory.MakeImportDropletCommand(),
		dropletRunnerCommandFactory.MakeExportDropletCommand(),
		sshCommandFactory.MakeSSHCommand(),
		versionCommandFactory.MakeSyncCommand(),
		versionCommandFactory.MakeVersionCommand(),
		helpCommand,
	}
}
Beispiel #11
0
	"github.com/cloudfoundry-incubator/ltc/exit_handler/fake_exit_handler"
	"github.com/cloudfoundry-incubator/ltc/receptor_client/fake_receptor_client_creator"
	"github.com/cloudfoundry-incubator/ltc/terminal"
	"github.com/cloudfoundry-incubator/ltc/test_helpers"
	"github.com/cloudfoundry-incubator/receptor/fake_receptor"
	"github.com/codegangsta/cli"
	"github.com/pivotal-golang/lager"
)

var _ = Describe("CliAppFactory", func() {

	var (
		fakeTargetVerifier           *fake_target_verifier.FakeTargetVerifier
		fakeReceptorClientCreator    *fake_receptor_client_creator.FakeCreator
		fakeExitHandler              *fake_exit_handler.FakeExitHandler
		outputBuffer                 *gbytes.Buffer
		terminalUI                   terminal.UI
		cliApp                       *cli.App
		cliConfig                    *config.Config
		latticeVersion, diegoVersion string
	)

	BeforeEach(func() {
		fakeTargetVerifier = &fake_target_verifier.FakeTargetVerifier{}
		fakeReceptorClientCreator = &fake_receptor_client_creator.FakeCreator{}
		fakeExitHandler = &fake_exit_handler.FakeExitHandler{}
		memPersister := persister.NewMemPersister()
		outputBuffer = gbytes.NewBuffer()
		terminalUI = terminal.NewUI(nil, outputBuffer, nil)
		cliConfig = config.New(memPersister)
		latticeVersion, diegoVersion = "v0.2.Test", "0.12345.0"
Beispiel #12
0
	"github.com/cloudfoundry-incubator/ltc/config/persister"
	"github.com/cloudfoundry-incubator/ltc/droplet_runner"
	"github.com/cloudfoundry-incubator/ltc/droplet_runner/fake_blob_store"
	"github.com/cloudfoundry-incubator/ltc/droplet_runner/fake_proxyconf_reader"
	"github.com/cloudfoundry-incubator/ltc/task_runner/fake_task_runner"
	"github.com/cloudfoundry-incubator/ltc/test_helpers/matchers"

	config_package "github.com/cloudfoundry-incubator/ltc/config"
)

var _ = Describe("DropletRunner", func() {
	var (
		fakeAppRunner       *fake_app_runner.FakeAppRunner
		fakeTaskRunner      *fake_task_runner.FakeTaskRunner
		config              *config_package.Config
		fakeBlobStore       *fake_blob_store.FakeBlobStore
		fakeAppExaminer     *fake_app_examiner.FakeAppExaminer
		fakeProxyConfReader *fake_proxyconf_reader.FakeProxyConfReader
		dropletRunner       droplet_runner.DropletRunner
	)

	BeforeEach(func() {
		fakeAppRunner = &fake_app_runner.FakeAppRunner{}
		fakeTaskRunner = &fake_task_runner.FakeTaskRunner{}
		config = config_package.New(persister.NewMemPersister())
		fakeBlobStore = &fake_blob_store.FakeBlobStore{}
		fakeAppExaminer = &fake_app_examiner.FakeAppExaminer{}
		fakeProxyConfReader = &fake_proxyconf_reader.FakeProxyConfReader{}
		dropletRunner = droplet_runner.New(fakeAppRunner, fakeTaskRunner, config, fakeBlobStore, fakeAppExaminer, fakeProxyConfReader)
	})
Beispiel #13
0
	"github.com/cloudfoundry-incubator/ltc/test_helpers"
	"github.com/cloudfoundry-incubator/ltc/version"
	"github.com/cloudfoundry-incubator/ltc/version/command_factory"
	"github.com/cloudfoundry-incubator/ltc/version/fake_version_manager"
	"github.com/codegangsta/cli"

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

var _ = Describe("Version CommandFactory", func() {
	var (
		config             *config_package.Config
		outputBuffer       *gbytes.Buffer
		terminalUI         terminal.UI
		fakeExitHandler    *fake_exit_handler.FakeExitHandler
		fakeVersionManager *fake_version_manager.FakeVersionManager
		commandFactory     *command_factory.VersionCommandFactory
	)

	BeforeEach(func() {
		config = config_package.New(nil)
		config.SetTarget("lattice.xip.io")

		outputBuffer = gbytes.NewBuffer()
		terminalUI = terminal.NewUI(nil, outputBuffer, nil)
		fakeExitHandler = &fake_exit_handler.FakeExitHandler{}
		fakeVersionManager = &fake_version_manager.FakeVersionManager{}
		fakeVersionManager.LtcVersionReturns("1.8.0")
		commandFactory = command_factory.NewVersionCommandFactory(
			config,
			verifier        blob_store.BlobStoreVerifier
			fakeDAVVerifier *fake_blob_store_verifier.FakeVerifier
			fakeS3Verifier  *fake_blob_store_verifier.FakeVerifier
		)

		BeforeEach(func() {
			fakeDAVVerifier = &fake_blob_store_verifier.FakeVerifier{}
			fakeS3Verifier = &fake_blob_store_verifier.FakeVerifier{}
			verifier = blob_store.BlobStoreVerifier{
				DAVBlobStoreVerifier: fakeDAVVerifier,
				S3BlobStoreVerifier:  fakeS3Verifier,
			}
		})

		Context("when a dav blob store is targeted", func() {
			var config *config_package.Config

			BeforeEach(func() {
				config = config_package.New(nil)
				config.SetBlobStore("some-host", "some-port", "some-user", "some-password")
			})

			It("returns a new DavBlobStore Verifier", func() {
				verifier.Verify(config)
				Expect(fakeDAVVerifier.VerifyCallCount()).To(Equal(1))
				Expect(fakeS3Verifier.VerifyCallCount()).To(Equal(0))
			})
		})

		Context("when an s3 blob store is targeted", func() {
			var config *config_package.Config
	"github.com/cloudfoundry-incubator/ltc/terminal/mocks"
	"github.com/cloudfoundry-incubator/ltc/test_helpers"
	"github.com/cloudfoundry-incubator/ltc/version/fake_version_manager"
	"github.com/codegangsta/cli"

	config_package "github.com/cloudfoundry-incubator/ltc/config"
)

var _ = Describe("CommandFactory", func() {
	var (
		stdinReader           *io.PipeReader
		stdinWriter           *io.PipeWriter
		outputBuffer          *gbytes.Buffer
		terminalUI            terminal.UI
		config                *config_package.Config
		configPersister       persister.Persister
		fakeTargetVerifier    *fake_target_verifier.FakeTargetVerifier
		fakeBlobStoreVerifier *fake_blob_store_verifier.FakeBlobStoreVerifier
		fakeExitHandler       *fake_exit_handler.FakeExitHandler
		fakePasswordReader    *mocks.FakePasswordReader
		fakeVersionManager    *fake_version_manager.FakeVersionManager
	)

	BeforeEach(func() {
		stdinReader, stdinWriter = io.Pipe()
		outputBuffer = gbytes.NewBuffer()
		fakeExitHandler = &fake_exit_handler.FakeExitHandler{}
		fakePasswordReader = &mocks.FakePasswordReader{}
		terminalUI = terminal.NewUI(stdinReader, outputBuffer, fakePasswordReader)
		fakeTargetVerifier = &fake_target_verifier.FakeTargetVerifier{}
		fakeBlobStoreVerifier = &fake_blob_store_verifier.FakeBlobStoreVerifier{}
import (
	"net/http"

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

	"github.com/cloudfoundry-incubator/ltc/blob_store/s3_blob_store"
	config_package "github.com/cloudfoundry-incubator/ltc/config"
)

var _ = Describe("S3BlobStore", func() {
	var (
		verifier   *s3_blob_store.Verifier
		fakeServer *ghttp.Server
		config     *config_package.Config
	)

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()
		verifier = &s3_blob_store.Verifier{fakeServer.URL()}
		config = config_package.New(nil)
		config.SetS3BlobStore("some-access-key", "some-secret-key", "bucket", "some-region")
	})

	Describe("Verify", func() {
		Context("when the blob store credentials are valid", func() {
			It("returns authorized as true", func() {
				responseBody := `
					 <?xml version="1.0" encoding="UTF-8"?>
	"errors"
	"reflect"

	config_package "github.com/cloudfoundry-incubator/ltc/config"
	sshp "github.com/cloudfoundry-incubator/ltc/ssh"
	"github.com/cloudfoundry-incubator/ltc/ssh/sshapi"
	"golang.org/x/crypto/ssh"

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

var _ = Describe("AppDialer", func() {
	Describe("#Dial", func() {
		var (
			origDial func(network, addr string, config *ssh.ClientConfig) (*ssh.Client, error)
			config   *config_package.Config
		)

		BeforeEach(func() {
			config = config_package.New(nil)
			config.SetTarget("some-host")
			config.SetLogin("some-user", "some-password")
			origDial = sshapi.DialFunc
		})

		AfterEach(func() {
			sshapi.DialFunc = origDial
		})

		It("should create a client", func() {
			dialCalled := false
	"github.com/onsi/gomega/ghttp"

	config_package "github.com/cloudfoundry-incubator/ltc/config"
	"github.com/cloudfoundry-incubator/ltc/receptor_client/fake_receptor_client_creator"
	"github.com/cloudfoundry-incubator/ltc/version"
	"github.com/cloudfoundry-incubator/ltc/version/fake_file_swapper"
	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/receptor/fake_receptor"
)

var _ = Describe("VersionManager", func() {
	var (
		fakeFileSwapper           *fake_file_swapper.FakeFileSwapper
		fakeServer                *ghttp.Server
		config                    *config_package.Config
		versionManager            version.VersionManager
		fakeReceptorClientCreator *fake_receptor_client_creator.FakeCreator
		fakeReceptorClient        *fake_receptor.FakeClient

		ltcTempFile *os.File
	)

	BeforeEach(func() {
		fakeFileSwapper = &fake_file_swapper.FakeFileSwapper{}

		fakeServer = ghttp.NewServer()
		fakeServerURL, err := url.Parse(fakeServer.URL())
		Expect(err).NotTo(HaveOccurred())

		fakeServerHost, fakeServerPort, err := net.SplitHostPort(fakeServerURL.Host)
		Expect(err).NotTo(HaveOccurred())
package config_test

import (
	"errors"

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

	"github.com/cloudfoundry-incubator/ltc/config"
)

var _ = Describe("Config", func() {
	var (
		testPersister *fakePersister
		testConfig    *config.Config
	)

	BeforeEach(func() {
		testPersister = &fakePersister{}
		testConfig = config.New(testPersister)
	})

	Describe("Target", func() {
		It("sets the target", func() {
			testConfig.SetTarget("mynewapi.com")

			Expect(testConfig.Target()).To(Equal("mynewapi.com"))
		})
	})

	Describe("Username", func() {