本文整理匯總了Golang中testhelpers/terminal.FakeUI類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeUI類的具體用法?Golang FakeUI怎麽用?Golang FakeUI使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeUI類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSpaceRequirement
func TestSpaceRequirement(t *testing.T) {
ui := new(testterm.FakeUI)
config := &configuration.Configuration{
Organization: cf.Organization{
Name: "my-org",
Guid: "my-org-guid",
},
Space: cf.Space{
Name: "my-space",
Guid: "my-space-guid",
},
}
req := newTargetedSpaceRequirement(ui, config)
success := req.Execute()
assert.True(t, success)
config.Space = cf.Space{}
req = newTargetedSpaceRequirement(ui, config)
success = req.Execute()
assert.False(t, success)
assert.Contains(t, ui.Outputs[0], "FAILED")
assert.Contains(t, ui.Outputs[1], "No space targeted")
ui.ClearOutputs()
config.Organization = cf.Organization{}
req = newTargetedSpaceRequirement(ui, config)
success = req.Execute()
assert.False(t, success)
assert.Contains(t, ui.Outputs[0], "FAILED")
assert.Contains(t, ui.Outputs[1], "No org and space targeted")
}
示例2: TestSpaceRequirement
func TestSpaceRequirement(t *testing.T) {
ui := new(testterm.FakeUI)
org := cf.OrganizationFields{}
org.Name = "my-org"
org.Guid = "my-org-guid"
space := cf.SpaceFields{}
space.Name = "my-space"
space.Guid = "my-space-guid"
config := &configuration.Configuration{
OrganizationFields: org,
SpaceFields: space,
}
req := newTargetedSpaceRequirement(ui, config)
success := req.Execute()
assert.True(t, success)
config.SpaceFields = cf.SpaceFields{}
req = newTargetedSpaceRequirement(ui, config)
success = req.Execute()
assert.False(t, success)
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"FAILED"},
{"No space targeted"},
})
ui.ClearOutputs()
config.OrganizationFields = cf.OrganizationFields{}
req = newTargetedSpaceRequirement(ui, config)
success = req.Execute()
assert.False(t, success)
testassert.SliceContains(t, ui.Outputs, testassert.Lines{
{"FAILED"},
{"No org and space targeted"},
})
}
示例3: init
func init() {
Describe("migrating service instances from v1 to v2", func() {
var (
ui *testterm.FakeUI
serviceRepo *testapi.FakeServiceRepo
cmd *MigrateServiceInstances
requirementsFactory *testreq.FakeReqFactory
context *cli.Context
args []string
)
BeforeEach(func() {
ui = &testterm.FakeUI{}
config := testconfig.NewRepository()
serviceRepo = &testapi.FakeServiceRepo{}
cmd = NewMigrateServiceInstances(ui, config, serviceRepo)
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
args = []string{}
})
Describe("requirements", func() {
It("requires you to be logged in", func() {
context = testcmd.NewContext("migrate-service-instances", args)
testcmd.RunCommand(cmd, context, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("requires five arguments to run", func() {
requirementsFactory.LoginSuccess = true
args = []string{"one", "two", "three"}
context = testcmd.NewContext("migrate-service-instances", args)
testcmd.RunCommand(cmd, context, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("passes requirements if user is logged in and provided five args to run", func() {
requirementsFactory.LoginSuccess = true
args = []string{"one", "two", "three", "four", "five"}
ui.Inputs = append(ui.Inputs, "no")
context = testcmd.NewContext("migrate-service-instances", args)
testcmd.RunCommand(cmd, context, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
})
})
Describe("migrating service instances", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
args = []string{"v1-service-name", "v1-provider-name", "v1-plan-name", "v2-service-name", "v2-plan-name"}
context = testcmd.NewContext("migrate-service-instances", args)
serviceRepo.ServiceInstanceCountForServicePlan = 1
})
It("displays the warning and the prompt including info about the instances and plan to migrate", func() {
ui.Inputs = []string{""}
testcmd.RunCommand(cmd, context, requirementsFactory)
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"WARNING:", "this operation is to replace a service broker"},
})
testassert.SliceContains(ui.Prompts, testassert.Lines{
{"Really migrate", "1 service instance",
"from plan", "v1-service-name", "v1-provider-name", "v1-plan-name",
"to", "v2-service-name", "v2-plan-name"},
})
})
Context("when the user confirms", func() {
BeforeEach(func() {
ui.Inputs = []string{"yes"}
})
Context("when the v1 and v2 service instances exists", func() {
BeforeEach(func() {
serviceRepo.FindServicePlanByDescriptionResultGuids = []string{"v1-guid", "v2-guid"}
serviceRepo.MigrateServicePlanFromV1ToV2ReturnedCount = 1
})
It("makes a request to migrate the v1 service instance", func() {
testcmd.RunCommand(cmd, context, requirementsFactory)
Expect(serviceRepo.V1GuidToMigrate).To(Equal("v1-guid"))
Expect(serviceRepo.V2GuidToMigrate).To(Equal("v2-guid"))
})
It("finds the v1 service plan by its name, provider and service label", func() {
testcmd.RunCommand(cmd, context, requirementsFactory)
expectedV1 := api.ServicePlanDescription{
ServicePlanName: "v1-plan-name",
ServiceProvider: "v1-provider-name",
ServiceName: "v1-service-name",
}
Expect(serviceRepo.FindServicePlanByDescriptionArguments[0]).To(Equal(expectedV1))
})
//.........這裏部分代碼省略.........
示例4:
package requirements_test
import (
"cf/models"
. "cf/requirements"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
testassert "testhelpers/assert"
testconfig "testhelpers/configuration"
testterm "testhelpers/terminal"
)
var _ = Describe("Testing with ginkgo", func() {
It("TestSpaceRequirement", func() {
ui := new(testterm.FakeUI)
org := models.OrganizationFields{}
org.Name = "my-org"
org.Guid = "my-org-guid"
space := models.SpaceFields{}
space.Name = "my-space"
space.Guid = "my-space-guid"
config := testconfig.NewRepositoryWithDefaults()
req := NewTargetedSpaceRequirement(ui, config)
success := req.Execute()
Expect(success).To(BeTrue())
config.SetSpaceFields(models.SpaceFields{})
testassert.AssertPanic(testterm.FailedWasCalled, func() {
示例5:
. "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{}
示例6:
"cf/errors"
"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("delete-service-auth-token command", func() {
var (
ui *testterm.FakeUI
configRepo configuration.ReadWriter
authTokenRepo *testapi.FakeAuthTokenRepo
requirementsFactory *testreq.FakeReqFactory
)
BeforeEach(func() {
ui = &testterm.FakeUI{Inputs: []string{"y"}}
authTokenRepo = &testapi.FakeAuthTokenRepo{}
configRepo = testconfig.NewRepositoryWithDefaults()
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
})
runCommand := func(args ...string) {
cmd := NewDeleteServiceAuthToken(ui, configRepo, authTokenRepo)
testcmd.RunCommand(cmd, testcmd.NewContext("delete-service-auth-token", args), requirementsFactory)
}
示例7:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
testapi "testhelpers/api"
testassert "testhelpers/assert"
testcmd "testhelpers/commands"
testconfig "testhelpers/configuration"
testterm "testhelpers/terminal"
)
var _ = Describe("Login Command", func() {
var (
Flags []string
Config configuration.ReadWriter
ui *testterm.FakeUI
authRepo *testapi.FakeAuthenticationRepository
endpointRepo *testapi.FakeEndpointRepo
orgRepo *testapi.FakeOrgRepository
spaceRepo *testapi.FakeSpaceRepository
)
BeforeEach(func() {
Flags = []string{}
Config = testconfig.NewRepository()
ui = &testterm.FakeUI{}
authRepo = &testapi.FakeAuthenticationRepository{
AccessToken: "my_access_token",
RefreshToken: "my_refresh_token",
Config: Config,
}
endpointRepo = &testapi.FakeEndpointRepo{}
示例8:
"cf/configuration"
"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("delete-org command", func() {
var (
config configuration.ReadWriter
ui *testterm.FakeUI
requirementsFactory *testreq.FakeReqFactory
orgRepo *testapi.FakeOrgRepository
)
BeforeEach(func() {
ui = &testterm.FakeUI{
Inputs: []string{"y"},
}
config = testconfig.NewRepositoryWithDefaults()
requirementsFactory = &testreq.FakeReqFactory{}
org := models.Organization{}
org.Name = "org-to-delete"
org.Guid = "org-to-delete-guid"
orgRepo = &testapi.FakeOrgRepository{Organizations: []models.Organization{org}}
})
示例9:
. "cf/commands/organization"
"cf/configuration"
"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("Testing with ginkgo", func() {
var config configuration.ReadWriter
var ui *testterm.FakeUI
var reqFactory *testreq.FakeReqFactory
var orgRepo *testapi.FakeOrgRepository
BeforeEach(func() {
reqFactory = &testreq.FakeReqFactory{}
ui = &testterm.FakeUI{}
spaceFields := models.SpaceFields{}
spaceFields.Name = "my-space"
orgFields := models.OrganizationFields{}
orgFields.Name = "my-org"
token := configuration.TokenInfo{Username: "my-user"}
示例10:
"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("delete-domain command", func() {
var (
cmd *DeleteDomain
ui *testterm.FakeUI
configRepo configuration.ReadWriter
domainRepo *testapi.FakeDomainRepository
requirementsFactory *testreq.FakeReqFactory
)
BeforeEach(func() {
ui = &testterm.FakeUI{
Inputs: []string{"yes"},
}
domainRepo = &testapi.FakeDomainRepository{}
requirementsFactory = &testreq.FakeReqFactory{
LoginSuccess: true,
TargetedOrgSuccess: true,
}
configRepo = testconfig.NewRepositoryWithDefaults()
示例11:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
testapi "testhelpers/api"
testassert "testhelpers/assert"
testcmd "testhelpers/commands"
testconfig "testhelpers/configuration"
"testhelpers/maker"
testreq "testhelpers/requirements"
testterm "testhelpers/terminal"
)
var _ = Describe("scale command", func() {
var (
reqFactory *testreq.FakeReqFactory
restarter *testcmd.FakeAppRestarter
appRepo *testapi.FakeApplicationRepository
ui *testterm.FakeUI
configRepo configuration.Repository
cmd *Scale
)
BeforeEach(func() {
reqFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true}
restarter = &testcmd.FakeAppRestarter{}
appRepo = &testapi.FakeApplicationRepository{}
ui = new(testterm.FakeUI)
configRepo = testconfig.NewRepositoryWithDefaults()
cmd = NewScale(ui, configRepo, restarter, appRepo)
})
Describe("requirements", func() {
It("requires the user to be logged in with a targed space", func() {
示例12:
"cf/configuration"
. "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("create-user-provided-service command", func() {
var (
ui *testterm.FakeUI
config configuration.ReadWriter
repo *testapi.FakeUserProvidedServiceInstanceRepo
requirementsFactory *testreq.FakeReqFactory
cmd CreateUserProvidedService
)
BeforeEach(func() {
ui = &testterm.FakeUI{}
config = testconfig.NewRepositoryWithDefaults()
repo = &testapi.FakeUserProvidedServiceInstanceRepo{}
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
cmd = NewCreateUserProvidedService(ui, config, repo)
})
Describe("login requirements", func() {
It("fails if the user is not logged in", func() {
requirementsFactory.LoginSuccess = false
示例13:
. "cf/commands/route"
"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("delete-route command", func() {
var (
routeRepo *testapi.FakeRouteRepository
reqFactory *testreq.FakeReqFactory
ui *testterm.FakeUI
cmd *DeleteRoute
)
BeforeEach(func() {
configRepo := testconfig.NewRepositoryWithDefaults()
ui = &testterm.FakeUI{}
routeRepo = &testapi.FakeRouteRepository{}
reqFactory = &testreq.FakeReqFactory{}
cmd = NewDeleteRoute(ui, configRepo, routeRepo)
})
var callDeleteRoute = func(confirmation string, args []string) {
ui.Inputs = []string{confirmation}
testcmd.RunCommand(cmd, testcmd.NewContext("delete-route", args), reqFactory)
}
示例14:
"cf/configuration"
. "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("auth command", func() {
var (
ui *testterm.FakeUI
cmd Authenticate
config configuration.ReadWriter
repo *testapi.FakeAuthenticationRepository
reqFactory *testreq.FakeReqFactory
)
BeforeEach(func() {
ui = &testterm.FakeUI{}
config = testconfig.NewRepositoryWithDefaults()
reqFactory = &testreq.FakeReqFactory{}
repo = &testapi.FakeAuthenticationRepository{
Config: config,
AccessToken: "my-access-token",
RefreshToken: "my-refresh-token",
}
cmd = NewAuthenticate(ui, config, repo)
})