本文整理匯總了Golang中github.com/nttlabs/cli/testhelpers/configuration.NewRepository函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRepository函數的具體用法?Golang NewRepository怎麽用?Golang NewRepository使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewRepository函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newCurlDependencies
func newCurlDependencies() (deps curlDependencies) {
deps.ui = &testterm.FakeUI{}
deps.config = testconfig.NewRepository()
deps.requirementsFactory = &testreq.FakeReqFactory{}
deps.curlRepo = &testapi.FakeCurlRepository{}
return
}
示例2: getPasswordDeps
func getPasswordDeps() passwordDeps {
return passwordDeps{
ReqFactory: &testreq.FakeReqFactory{LoginSuccess: true},
PwdRepo: &testapi.FakePasswordRepo{UpdateUnauthorized: true},
Config: testconfig.NewRepository(),
}
}
示例3: setupDependencies
func setupDependencies() (obj commandDependencies) {
obj.ui = &testterm.FakeUI{}
obj.config = testconfig.NewRepository()
obj.requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true}
obj.serviceRepo = new(testapi.FakeServiceRepo)
return
}
示例4: createAuthenticationRepository
func createAuthenticationRepository(apiServer *httptest.Server, authServer *httptest.Server) (core_config.ReadWriter, authentication.AuthenticationRepository) {
config := testconfig.NewRepository()
config.SetAuthenticationEndpoint(authServer.URL)
config.SetApiEndpoint(apiServer.URL)
config.SetAccessToken("bearer initial-access-token")
config.SetRefreshToken("initial-refresh-token")
authGateway := NewUAAGateway(config, &testterm.FakeUI{})
authGateway.SetTrustedCerts(authServer.TLS.Certificates)
authenticator := authentication.NewUAAAuthenticationRepository(authGateway, config)
return config, authenticator
}
示例5: createCommandFactory
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)
}
示例6: findCommand
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
}
示例7:
. "github.com/onsi/gomega"
. "github.com/nttlabs/cli/testhelpers/matchers"
)
var _ = Describe("bind-service command", func() {
var (
requirementsFactory *testreq.FakeReqFactory
)
BeforeEach(func() {
requirementsFactory = &testreq.FakeReqFactory{}
})
It("fails requirements when not logged in", func() {
cmd := NewBindService(&testterm.FakeUI{}, testconfig.NewRepository(), &testapi.FakeServiceBindingRepo{})
testcmd.RunCommand(cmd, []string{"service", "app"}, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
It("binds a service instance to an app", func() {
app := models.Application{}
app.Name = "my-app"
app.Guid = "my-app-guid"
serviceInstance := models.ServiceInstance{}
示例8:
jsonResponse := `{ "code": 210003, "description": "The host is taken: test1" }`
fmt.Fprintln(writer, jsonResponse)
}
var invalidTokenCloudControllerRequest = func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusBadRequest)
jsonResponse := `{ "code": 1000, "description": "The token is invalid" }`
fmt.Fprintln(writer, jsonResponse)
}
var _ = Describe("Cloud Controller Gateway", func() {
var gateway Gateway
var config core_config.Reader
BeforeEach(func() {
config = testconfig.NewRepository()
gateway = NewCloudControllerGateway(config, time.Now, &testterm.FakeUI{})
})
It("parses error responses", func() {
ts := httptest.NewTLSServer(http.HandlerFunc(failingCloudControllerRequest))
defer ts.Close()
gateway.SetTrustedCerts(ts.TLS.Certificates)
request, apiErr := gateway.NewRequest("GET", ts.URL, "TOKEN", nil)
_, apiErr = gateway.PerformRequest(request)
Expect(apiErr).NotTo(BeNil())
Expect(apiErr.Error()).To(ContainSubstring("The host is taken: test1"))
Expect(apiErr.(errors.HttpError).ErrorCode()).To(ContainSubstring("210003"))
})
示例9:
var ui *testterm.FakeUI
BeforeEach(func() {
ui = new(testterm.FakeUI)
})
It("succeeds when given a config with an API endpoint and authentication", func() {
config := testconfig.NewRepositoryWithAccessToken(core_config.TokenInfo{Username: "my-user"})
config.SetApiEndpoint("api.example.com")
req := NewLoginRequirement(ui, config)
success := req.Execute()
Expect(success).To(BeTrue())
})
It("fails when given a config with only an API endpoint", func() {
config := testconfig.NewRepository()
config.SetApiEndpoint("api.example.com")
req := NewLoginRequirement(ui, config)
success := req.Execute()
Expect(success).To(BeFalse())
Expect(ui.Outputs).To(ContainSubstrings([]string{"Not logged in."}))
})
It("fails when given a config with neither an API endpoint nor authentication", func() {
config := testconfig.NewRepository()
req := NewLoginRequirement(ui, config)
success := req.Execute()
Expect(success).To(BeFalse())
Expect(ui.Outputs).To(ContainSubstrings([]string{"No API endpoint"}))
示例10:
app.Name = "my-app"
app.Guid = "my-app-guid"
serviceInstance.Name = "my-service"
serviceInstance.Guid = "my-service-guid"
requirementsFactory = &testreq.FakeReqFactory{}
requirementsFactory.Application = app
requirementsFactory.ServiceInstance = serviceInstance
serviceBindingRepo = &testapi.FakeServiceBindingRepo{}
})
Context("when not logged in", func() {
It("fails requirements when not logged in", func() {
cmd := NewUnbindService(&testterm.FakeUI{}, testconfig.NewRepository(), serviceBindingRepo)
testcmd.RunCommand(cmd, []string{"my-service", "my-app"}, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
Context("when the service instance exists", func() {
It("unbinds a service from an app", func() {
ui := callUnbindService([]string{"my-app", "my-service"}, requirementsFactory, serviceBindingRepo)
Expect(requirementsFactory.ApplicationName).To(Equal("my-app"))
示例11:
logsForTail = []*logmessage.LogMessage{
testlogs.NewLogMessage("Log Line 1", app.Guid, LogMessageTypeStaging, time.Now()),
testlogs.NewLogMessage("Log Line 2", app.Guid, LogMessageTypeStaging, time.Now()),
}
args := []string{"my-app"}
requirementsFactory.Application = app
ui = callStart(args, configRepo, requirementsFactory, displayApp, appRepo, appInstancesRepo, logRepo)
return
}
It("fails requirements when not logged in", func() {
requirementsFactory.LoginSuccess = false
cmd := NewStart(new(testterm.FakeUI), testconfig.NewRepository(), &testcmd.FakeAppDisplayer{}, &testApplication.FakeApplicationRepository{}, &testAppInstanaces.FakeAppInstancesRepository{}, &testapi.FakeLogsRepository{})
testcmd.RunCommand(cmd, []string{"some-app-name"}, requirementsFactory)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
Describe("timeouts", func() {
It("has sane default timeout values", func() {
cmd := NewStart(new(testterm.FakeUI), testconfig.NewRepository(), &testcmd.FakeAppDisplayer{}, &testApplication.FakeApplicationRepository{}, &testAppInstanaces.FakeAppInstancesRepository{}, &testapi.FakeLogsRepository{})
Expect(cmd.StagingTimeout).To(Equal(15 * time.Minute))
Expect(cmd.StartupTimeout).To(Equal(5 * time.Minute))
})
It("can read timeout values from environment variables", func() {
oldStaging := os.Getenv("CF_STAGING_TIMEOUT")
oldStart := os.Getenv("CF_STARTUP_TIMEOUT")
defer func() {