當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.Application類代碼示例

本文整理匯總了Golang中cf/models.Application的典型用法代碼示例。如果您正苦於以下問題:Golang Application類的具體用法?Golang Application怎麽用?Golang Application使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Application類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: bindAppToRoute

func (cmd *Push) bindAppToRoute(app models.Application, params models.AppParams, c *cli.Context) {
	if params.NoRoute {
		if len(app.Routes) == 0 {
			cmd.ui.Say("App %s is a worker, skipping route creation", terminal.EntityNameColor(app.Name))
		} else {
			for _, route := range app.Routes {
				cmd.ui.Say("Removing route %s...", terminal.EntityNameColor(route.URL()))
				cmd.routeRepo.Unbind(route.Guid, app.Guid)
			}
		}

		return
	}

	routeFlagsPresent := c.String("n") != "" || c.String("d") != "" || c.Bool("no-hostname")
	if len(app.Routes) > 0 && !routeFlagsPresent {
		return
	}

	domain := cmd.findDomain(params)
	hostname := cmd.hostnameForApp(params, c)

	route, apiErr := cmd.routeRepo.FindByHostAndDomain(hostname, domain.Name)

	switch apiErr.(type) {
	case nil:
		cmd.ui.Say("Using route %s", terminal.EntityNameColor(route.URL()))
	case *errors.ModelNotFoundError:
		cmd.ui.Say("Creating route %s...", terminal.EntityNameColor(domain.UrlForHost(hostname)))

		route, apiErr = cmd.routeRepo.Create(hostname, domain.Guid)
		if apiErr != nil {
			cmd.ui.Failed(apiErr.Error())
		}

		cmd.ui.Ok()
		cmd.ui.Say("")
	default:
		cmd.ui.Failed(apiErr.Error())
	}

	if !app.HasRoute(route) {
		cmd.ui.Say("Binding %s to %s...", terminal.EntityNameColor(domain.UrlForHost(hostname)), terminal.EntityNameColor(app.Name))

		apiErr = cmd.routeRepo.Bind(route.Guid, app.Guid)
		switch apiErr := apiErr.(type) {
		case nil:
			cmd.ui.Ok()
			cmd.ui.Say("")
			return
		case errors.HttpError:
			if apiErr.ErrorCode() == errors.INVALID_RELATION {
				cmd.ui.Failed("The route %s is already in use.\nTIP: Change the hostname with -n HOSTNAME or use --random-route to generate a new route and then push again.", route.URL())
			}
		}
		cmd.ui.Failed(apiErr.Error())
	}
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:58,代碼來源:push.go

示例2: testDisplayingAppSummaryWithErrorCode

func testDisplayingAppSummaryWithErrorCode(errorCode string) {
	reqApp := models.Application{}
	reqApp.Name = "my-app"
	reqApp.Guid = "my-app-guid"

	domain3 := models.DomainFields{}
	domain3.Name = "example.com"
	domain4 := models.DomainFields{}
	domain4.Name = "example.com"

	route1 := models.RouteSummary{}
	route1.Host = "my-app"
	route1.Domain = domain3

	route2 := models.RouteSummary{}
	route2.Host = "foo"
	route2.Domain = domain4

	routes := []models.RouteSummary{
		route1,
		route2,
	}

	app := models.ApplicationFields{}
	app.State = "stopped"
	app.InstanceCount = 2
	app.RunningInstances = 0
	app.Memory = 256

	appSummary := models.AppSummary{}
	appSummary.ApplicationFields = app
	appSummary.RouteSummaries = routes

	appSummaryRepo := &testapi.FakeAppSummaryRepo{GetSummarySummary: appSummary, GetSummaryErrorCode: errorCode}
	appInstancesRepo := &testapi.FakeAppInstancesRepo{}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: reqApp}
	ui := callApp([]string{"my-app"}, reqFactory, appSummaryRepo, appInstancesRepo)

	Expect(appSummaryRepo.GetSummaryAppGuid).To(Equal("my-app-guid"))
	Expect(appInstancesRepo.GetInstancesAppGuid).To(Equal("my-app-guid"))

	testassert.SliceContains(ui.Outputs, testassert.Lines{
		{"Showing health and status", "my-app", "my-org", "my-space", "my-user"},
		{"state", "stopped"},
		{"instances", "0/2"},
		{"usage", "256M x 2 instances"},
		{"urls", "my-app.example.com, foo.example.com"},
		{"no running instances"},
	})
}
開發者ID:juggernaut,項目名稱:cli,代碼行數:50,代碼來源:show_app_test.go

示例3: deleteApp

func deleteApp(confirmation string, args []string) (ui *testterm.FakeUI, reqFactory *testreq.FakeReqFactory, appRepo *testapi.FakeApplicationRepository) {

	app := models.Application{}
	app.Name = "app-to-delete"
	app.Guid = "app-to-delete-guid"

	reqFactory = &testreq.FakeReqFactory{}
	appRepo = &testapi.FakeApplicationRepository{ReadApp: app}
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}

	configRepo := testconfig.NewRepositoryWithDefaults()

	ctxt := testcmd.NewContext("delete", args)
	cmd := NewDeleteApp(ui, configRepo, appRepo)
	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:19,代碼來源:delete_app_test.go

示例4: makeAppWithRoute

func makeAppWithRoute(appName string) models.Application {
	application := models.Application{}
	application.Name = appName
	application.Guid = "app-guid"

	domain := models.DomainFields{}
	domain.Name = "example.com"

	route := models.RouteSummary{Host: "foo", Domain: domain}
	secondRoute := models.RouteSummary{Host: appName, Domain: domain}

	application.State = "started"
	application.InstanceCount = 2
	application.RunningInstances = 2
	application.Memory = 256
	application.Routes = []models.RouteSummary{route, secondRoute}

	return application
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:19,代碼來源:app_test.go

示例5:

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"os"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testcmd "testhelpers/commands"
	testconfig "testhelpers/configuration"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
	"time"
)

var _ = Describe("Testing with ginkgo", func() {
	var (
		defaultAppForStart        = models.Application{}
		defaultInstanceReponses   = [][]models.AppInstanceFields{}
		defaultInstanceErrorCodes = []string{"", ""}
		defaultStartTimeout       = 50 * time.Millisecond
	)

	BeforeEach(func() {
		defaultAppForStart.Name = "my-app"
		defaultAppForStart.Guid = "my-app-guid"
		defaultAppForStart.InstanceCount = 2

		domain := models.DomainFields{}
		domain.Name = "example.com"

		route := models.RouteSummary{}
		route.Host = "my-app"
		route.Domain = domain
開發者ID:juggernaut,項目名稱:cli,代碼行數:31,代碼來源:start_test.go

示例6:

}

var _ = Describe("Testing with ginkgo", func() {
	It("TestRestartCommandFailsWithUsage", func() {
		requirementsFactory := &testreq.FakeReqFactory{}
		starter := &testcmd.FakeAppStarter{}
		stopper := &testcmd.FakeAppStopper{}
		ui := callRestart([]string{}, requirementsFactory, starter, stopper)
		Expect(ui.FailedWithUsage).To(BeTrue())

		ui = callRestart([]string{"my-app"}, requirementsFactory, starter, stopper)
		Expect(ui.FailedWithUsage).To(BeFalse())
	})
	It("TestRestartRequirements", func() {

		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
		starter := &testcmd.FakeAppStarter{}
		stopper := &testcmd.FakeAppStopper{}

		requirementsFactory := &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: true}
		callRestart([]string{"my-app"}, requirementsFactory, starter, stopper)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		requirementsFactory = &testreq.FakeReqFactory{Application: app, LoginSuccess: false, TargetedSpaceSuccess: true}
		callRestart([]string{"my-app"}, requirementsFactory, starter, stopper)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		requirementsFactory = &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: false}
		callRestart([]string{"my-app"}, requirementsFactory, starter, stopper)
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:restart_test.go

示例7:

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testcmd "testhelpers/commands"
	testconfig "testhelpers/configuration"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
)

var _ = Describe("delete app command", func() {
	var (
		cmd                 *DeleteApp
		ui                  *testterm.FakeUI
		app                 models.Application
		configRepo          configuration.ReadWriter
		appRepo             *testapi.FakeApplicationRepository
		routeRepo           *testapi.FakeRouteRepository
		requirementsFactory *testreq.FakeReqFactory
	)

	BeforeEach(func() {
		app = models.Application{}
		app.Name = "app-to-delete"
		app.Guid = "app-to-delete-guid"

		ui = &testterm.FakeUI{}
		appRepo = &testapi.FakeApplicationRepository{}
		routeRepo = &testapi.FakeRouteRepository{}
		requirementsFactory = &testreq.FakeReqFactory{}
開發者ID:nota-ja,項目名稱:cli,代碼行數:30,代碼來源:delete_test.go

示例8: getEnvDependencies

func getEnvDependencies() (reqFactory *testreq.FakeReqFactory) {
	app := models.Application{}
	app.Name = "my-app"
	reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, Application: app}
	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:6,代碼來源:env_test.go

示例9:

		route2 := models.RouteSummary{}
		route2.Host = "app1"
		route2.Domain = domain2

		app1Routes := []models.RouteSummary{route1, route2}

		domain3 := models.DomainFields{}
		domain3.Name = "cfapps.io"

		route3 := models.RouteSummary{}
		route3.Host = "app2"
		route3.Domain = domain3

		app2Routes := []models.RouteSummary{route3}

		app := models.Application{}
		app.Name = "Application-1"
		app.State = "started"
		app.RunningInstances = 1
		app.InstanceCount = 1
		app.Memory = 512
		app.DiskQuota = 1024
		app.Routes = app1Routes

		app2 := models.Application{}
		app2.Name = "Application-2"
		app2.State = "started"
		app2.RunningInstances = 1
		app2.InstanceCount = 2
		app2.Memory = 256
		app2.DiskQuota = 1024
開發者ID:julz,項目名稱:cli,代碼行數:31,代碼來源:list_apps_test.go

示例10:

	"cf/api"
	. "cf/commands/application"
	"cf/models"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	testapi "testhelpers/api"
	testassert "testhelpers/assert"
	testcmd "testhelpers/commands"
	testconfig "testhelpers/configuration"
	testreq "testhelpers/requirements"
	testterm "testhelpers/terminal"
)

var _ = Describe("set-env command", func() {
	It("TestSetEnvRequirements", func() {
		app := models.Application{}
		app.Name = "my-app"
		app.Guid = "my-app-guid"
		appRepo := &testapi.FakeApplicationRepository{}
		args := []string{"my-app", "DATABASE_URL", "mysql://example.com/my-db"}

		reqFactory := &testreq.FakeReqFactory{Application: app, LoginSuccess: true, TargetedSpaceSuccess: true}
		callSetEnv(args, reqFactory, appRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())

		reqFactory = &testreq.FakeReqFactory{Application: app, LoginSuccess: false, TargetedSpaceSuccess: true}
		callSetEnv(args, reqFactory, appRepo)
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())

		testcmd.CommandDidPassRequirements = true
開發者ID:knolleary,項目名稱:cli,代碼行數:30,代碼來源:set_env_test.go

示例11:

		Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
		Expect(reqFactory.ApplicationName).To(Equal("my-app"))
	})

	It("requires an app name", func() {
		appSummaryRepo := &testapi.FakeAppSummaryRepo{}
		appInstancesRepo := &testapi.FakeAppInstancesRepo{}
		reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, Application: models.Application{}}
		ui := callApp([]string{}, reqFactory, appSummaryRepo, appInstancesRepo)

		Expect(ui.FailedWithUsage).To(BeTrue())
		Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
	})

	It("displays a summary of the app", func() {
		reqApp := models.Application{}
		reqApp.Name = "my-app"
		reqApp.Guid = "my-app-guid"

		route1 := models.RouteSummary{}
		route1.Host = "my-app"

		domain := models.DomainFields{}
		domain.Name = "example.com"
		route1.Domain = domain

		route2 := models.RouteSummary{}
		route2.Host = "foo"
		domain2 := models.DomainFields{}
		domain2.Name = "example.com"
		route2.Domain = domain2
開發者ID:julz,項目名稱:cli,代碼行數:31,代碼來源:show_app_test.go

示例12:

		Expect(handler.AllRequestsCalled()).To(BeTrue())
		Expect(apiResponse.IsNotSuccessful()).To(BeFalse())
	})

	It("TestCreateApplication", func() {
		ts, handler, repo := createAppRepo([]testnet.TestRequest{createApplicationRequest})
		defer ts.Close()

		params := defaultAppParams()
		createdApp, apiResponse := repo.Create(params)

		Expect(handler.AllRequestsCalled()).To(BeTrue())
		Expect(apiResponse.IsSuccessful()).To(BeTrue())

		app := models.Application{}
		app.Name = "my-cool-app"
		app.Guid = "my-cool-app-guid"
		Expect(createdApp).To(Equal(app))
	})

	It("TestCreateApplicationWithoutBuildpackStackOrCommand", func() {
		request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
			Method:   "POST",
			Path:     "/v2/apps",
			Matcher:  testnet.RequestBodyMatcher(`{"name":"my-cool-app","instances":3,"memory":2048,"space_guid":"some-space-guid"}`),
			Response: testnet.TestResponse{Status: http.StatusCreated, Body: createApplicationResponse},
		})

		ts, handler, repo := createAppRepo([]testnet.TestRequest{request})
		defer ts.Close()
開發者ID:normalnorman,項目名稱:cli,代碼行數:30,代碼來源:applications_test.go

示例13:

			Expect(apiErr.(*errors.ModelNotFoundError)).NotTo(BeNil())
		})
	})

	Describe("creating applications", func() {
		It("makes the right request", func() {
			ts, handler, repo := createAppRepo([]testnet.TestRequest{createApplicationRequest})
			defer ts.Close()

			params := defaultAppParams()
			createdApp, apiErr := repo.Create(params)

			Expect(handler).To(testnet.HaveAllRequestsCalled())
			Expect(apiErr).NotTo(HaveOccurred())

			app := models.Application{}
			app.Name = "my-cool-app"
			app.Guid = "my-cool-app-guid"
			Expect(createdApp).To(Equal(app))
		})

		It("omits fields that are not set", func() {
			request := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "POST",
				Path:     "/v2/apps",
				Matcher:  testnet.RequestBodyMatcher(`{"name":"my-cool-app","instances":3,"memory":2048,"disk_quota":512,"space_guid":"some-space-guid"}`),
				Response: testnet.TestResponse{Status: http.StatusCreated, Body: createApplicationResponse},
			})

			ts, handler, repo := createAppRepo([]testnet.TestRequest{request})
			defer ts.Close()
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:applications_test.go

示例14:

			It("fails when a non-numeric start timeout is given", func() {
				appRepo.ReadReturns.Error = errors.NewModelNotFoundError("App", "the-app")

				callPush(
					"-t", "FooeyTimeout",
					"my-new-app",
				)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"FAILED"},
					{"invalid", "timeout"},
				})
			})

			It("resets the app's command when the -c flag is provided as 'null'", func() {
				existingApp := models.Application{}
				existingApp.Name = "existing-app"
				existingApp.Guid = "existing-app-guid"
				existingApp.Command = "unicorn -c config/unicorn.rb -D"

				appRepo.ReadReturns.App = existingApp

				callPush("-c", "null", "existing-app")

				Expect(*appRepo.UpdateParams.Command).To(Equal(""))
			})

			It("resets the app's buildpack when the -b flag is provided as 'null'", func() {
				existingApp := models.Application{}
				existingApp.Name = "existing-app"
				existingApp.Guid = "existing-app-guid"
開發者ID:julz,項目名稱:cli,代碼行數:31,代碼來源:push_test.go

示例15:

				Expect(*appRepo.CreateAppParams[0].Name).To(Equal("app2"))
			})

			It("fails when given the name of an app that is not in the manifest", func() {
				callPush("non-existant-app")

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Failed"},
				})
				Expect(len(appRepo.CreateAppParams)).To(Equal(0))
			})
		})
	})

	Describe("re-pushing an existing app", func() {
		var existingApp models.Application

		BeforeEach(func() {
			existingApp = models.Application{}
			existingApp.Name = "existing-app"
			existingApp.Guid = "existing-app-guid"
			existingApp.Command = "unicorn -c config/unicorn.rb -D"
			existingApp.EnvironmentVars = map[string]string{
				"crazy": "pants",
				"FOO":   "NotYoBaz",
				"foo":   "manchu",
			}

			appRepo.ReadReturns.App = existingApp
			appRepo.UpdateAppResult = existingApp
		})
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:push_test.go


注:本文中的cf/models.Application類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。