func (s *AgentToolsSuite) TestUpdateToolsAvailabilityNoMatches(c *gc.C) { fakeNewEnvirons := func(*config.Config) (environs.Environ, error) { return dummyEnviron{}, nil } s.PatchValue(&newEnvirons, fakeNewEnvirons) fakeEnvConfig := func(_ *state.Model) (*config.Config, error) { sConfig := coretesting.FakeConfig() sConfig = sConfig.Merge(coretesting.Attrs{ "agent-version": "2.5.0", }) return config.New(config.NoDefaults, sConfig) } s.PatchValue(&envConfig, fakeEnvConfig) // No new tools available. fakeToolFinder := func(_ environs.Environ, _ int, _ int, _ string, _ coretools.Filter) (coretools.List, error) { return nil, errors.NotFoundf("tools") } // Update should never be called. fakeUpdate := func(_ *state.Model, v version.Number) error { c.Fail() return nil } err := updateToolsAvailability(&modelGetter{}, fakeToolFinder, fakeUpdate) c.Assert(err, jc.ErrorIsNil) }
func (s *clientSuite) TestClientModelUsers(c *gc.C) { client := s.APIState.Client() cleanup := api.PatchClientFacadeCall(client, func(request string, paramsIn interface{}, response interface{}) error { c.Assert(paramsIn, gc.IsNil) if response, ok := response.(*params.ModelUserInfoResults); ok { response.Results = []params.ModelUserInfoResult{ {Result: ¶ms.ModelUserInfo{UserName: "******"}}, {Result: ¶ms.ModelUserInfo{UserName: "******"}}, {Result: ¶ms.ModelUserInfo{UserName: "******"}}, } } else { c.Log("wrong output structure") c.Fail() } return nil }, ) defer cleanup() obtained, err := client.ModelUserInfo() c.Assert(err, jc.ErrorIsNil) c.Assert(obtained, jc.DeepEquals, []params.ModelUserInfo{ {UserName: "******"}, {UserName: "******"}, {UserName: "******"}, }) }
func (s *restoreSuite) TestFailedRestoreReboostrapMaintainsControllerInfo(c *gc.C) { metadata := params.BackupsMetadataResult{ CACert: testing.CACert, CAPrivateKey: testing.CAKey, } s.command = backups.NewRestoreCommandForTest( s.store, &mockRestoreAPI{}, func(string) (backups.ArchiveReader, *params.BackupsMetadataResult, error) { return &mockArchiveReader{}, &metadata, nil }, nil, backups.GetRebootstrapParamsFuncWithError(), ) s.PatchValue(&backups.BootstrapFunc, func(ctx environs.BootstrapContext, environ environs.Environ, args bootstrap.BootstrapParams) error { // We should not call bootstrap. c.Fail() return nil }) _, err := testing.RunCommand(c, s.command, "restore", "-m", "testing:test1", "--file", "afile", "-b") c.Assert(err, gc.ErrorMatches, "failed") // The details below are as per what was done in test setup, so no changes. c.Assert(s.store.Controllers["testing"], jc.DeepEquals, jujuclient.ControllerDetails{ Cloud: "mycloud", CloudRegion: "a-region", CACert: testing.CACert, ControllerUUID: "deadbeef-0bad-400d-8000-5b1d0d06f00d", APIEndpoints: []string{"10.0.1.1:17777"}, UnresolvedAPIEndpoints: []string{"10.0.1.1:17777"}, }) }
func mockAPICaller(c *gc.C, callNumber *int32, apiCalls ...apiCall) apitesting.APICallerFunc { apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { switch objType { case "NotifyWatcher": return nil case "Uniter": index := int(atomic.AddInt32(callNumber, 1)) - 1 c.Check(index < len(apiCalls), jc.IsTrue) call := apiCalls[index] c.Logf("request %d, %s", index, request) c.Check(version, gc.Equals, 4) c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, call.request) c.Check(arg, jc.DeepEquals, call.args) if call.err != nil { return common.ServerError(call.err) } testing.PatchValue(result, call.result) default: c.Fail() } return nil }) return apiCaller }
func checkToolsContent(c *gc.C, data []byte, uploaded string) { zr, err := gzip.NewReader(bytes.NewReader(data)) c.Check(err, jc.ErrorIsNil) defer zr.Close() tr := tar.NewReader(zr) found := false for { hdr, err := tr.Next() if err == io.EOF { break } c.Check(err, jc.ErrorIsNil) if strings.ContainsAny(hdr.Name, "/\\") { c.Fail() } if hdr.Typeflag != tar.TypeReg { c.Fail() } content, err := ioutil.ReadAll(tr) c.Check(err, jc.ErrorIsNil) c.Check(string(content), gc.Equals, uploaded) found = true } c.Check(found, jc.IsTrue) }
// startReading starts a goroutine receiving the lines out of the reader // in the background and passing them to a created string channel. This // will used in the assertions. func startReading(c *gc.C, tailer *tailer.Tailer, reader *io.PipeReader, writer *io.PipeWriter) chan string { linec := make(chan string) // Start goroutine for reading. go func() { defer close(linec) reader := bufio.NewReader(reader) for { line, err := reader.ReadString('\n') switch err { case nil: linec <- line case io.EOF: return default: c.Fail() } } }() // Close writer when tailer is stopped or has an error. Tailer using // components can do it the same way. go func() { tailer.Wait() writer.Close() }() return linec }
func (s *clientSuite) TestUnshareEnvironmentThreeUsers(c *gc.C) { client := s.APIState.Client() missingUser := s.Factory.MakeEnvUser(c, nil) localUser := s.Factory.MakeUser(c, nil) newUserTag := names.NewUserTag("foo@bar") cleanup := api.PatchClientFacadeCall(client, func(request string, paramsIn interface{}, response interface{}) error { if users, ok := paramsIn.(params.ModifyEnvironUsers); ok { c.Assert(users.Changes, gc.HasLen, 3) c.Assert(string(users.Changes[0].Action), gc.Equals, string(params.RemoveEnvUser)) c.Assert(users.Changes[0].UserTag, gc.Equals, missingUser.UserTag().String()) c.Assert(string(users.Changes[1].Action), gc.Equals, string(params.RemoveEnvUser)) c.Assert(users.Changes[1].UserTag, gc.Equals, localUser.UserTag().String()) c.Assert(string(users.Changes[2].Action), gc.Equals, string(params.RemoveEnvUser)) c.Assert(users.Changes[2].UserTag, gc.Equals, newUserTag.String()) } else { c.Log("wrong input structure") c.Fail() } if result, ok := response.(*params.ErrorResults); ok { err := ¶ms.Error{Message: "error unsharing user"} *result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}, {Error: nil}, {Error: nil}}} } else { c.Log("wrong output structure") c.Fail() } return nil }, ) defer cleanup() err := client.UnshareEnvironment(missingUser.UserTag(), localUser.UserTag(), newUserTag) c.Assert(err, gc.ErrorMatches, "error unsharing user") }
func (s *UpgraderSuite) expectUpgradeChannelNotClosed(c *gc.C) { select { case <-s.agentUpgradeComplete: c.Fail() default: } }
func (s *UnitSuite) TestAid(t *check.C) { host, err := os.Hostname() if err != nil { host = _HOST } a := NewAid() if a.Generate() != host+"-1" { t.Fail() } }
func (s *ZpSuite) TestMismatchedP(c *gc.C) { defer func() { r := recover() c.Assert(r, gc.NotNil) }() a := zp5(1) b := Zi(p(65537), 9) a.Add(a, b) c.Fail() }
func (i *IntegrationSuite) TestRedirect(c *check.C) { ch := make(chan Message) check := func(m Message) { ch <- m } a.Redirect("sip/1234", "new", "1000", "1", &check) r := <-ch if r["Response"] != "Error" { c.Fail() } }
func (i *IntegrationSuite) TestOriginate(c *check.C) { o := NewOriginateApp("sip/1234", "playback", "hello-world") ch := make(chan Message) check := func(m Message) { ch <- m } a.Originate(o, nil, &check) r := <-ch if r["Response"] != "Error" { c.Fail() } }
func (s *syslogConfigSuite) assertRsyslogConfigContents(c *gc.C, slConfig *syslog.SyslogConfig, expectedConf string) { data, err := slConfig.Render() c.Assert(err, jc.ErrorIsNil) if len(data) == 0 { c.Fatal("got empty data from render") } d := string(data) if d != expectedConf { diff(c, d, expectedConf) c.Fail() } }
func (i *IntegrationSuite) TestUserEvent(c *check.C) { ch := make(chan Message) check := func(m Message) { ch <- m } a.RegisterHandler("UserEvent", &check) a.UserEvent("TestEvent", map[string]string{"Key1": "Val1", "Key2": "Val2"}, nil) r := <-ch if r["UserEvent"] != "TestEvent" || r["Key1"] != "Val1" || r["Key2"] != "Val2" { c.Fail() } }
func (s *UnitSuite) TestCb(t *check.C) { cb := cbList{ &sync.RWMutex{}, make(map[string]*func(Message)), make(map[string]bool), } tf := func(m Message) {} k := "test1" cb.set(k, &tf, true) if cb.f[k] == nil || cb.sd[k] != true { t.Fail() } f, sd := cb.get(k) if f != &tf || !sd { t.Fail() } cb.del(k) if _, e := cb.f[k]; e { t.Fail() } if _, e := cb.sd[k]; e { t.Fail() } }
func (i *IntegrationSuite) TestDb(c *check.C) { ch := make(chan Message) check := func(m Message) { ch <- m } a.RegisterHandler("DbGetResponse", &check) a.DbPut("test", "newkey", "1000", nil) a.DbGet("test", "newkey", nil) r := <-ch if r["Val"] != "1000" { c.Fail() } a.UnregisterHandler("DbGetResponse") a.DbDelTree("test", "", nil) a.DbGet("test", "newkey", &check) r = <-ch if r["Response"] != "Error" { c.Fail() } }
func (i *IntegrationSuite) TestConferenceDestroy(c *check.C) { ch := make(chan Message) check := func(m Message) { ch <- m } cnt := 3 o := NewOriginateApp("fakeconference/conf2", "", "") for i := 0; i < cnt; i++ { a.Originate(o, nil, &check) r := <-ch if r["Response"] != "Success" { c.Fail() } } mbrs, _ := a.GetConfbridgeList("conf2") if len(mbrs) != cnt { c.Fail() } a.ConfbridgeKick("conf2", "all", nil) mbrs, _ = a.GetConfbridgeList("conf2") if len(mbrs) != 0 { c.Fail() } }
func (s *StorageBlobSuite) Test_SharedKeyLite(c *chk.C) { cli := getTableClient(c) // override the accountKey and accountName // but make sure to reset when returning oldAK := cli.client.accountKey oldAN := cli.client.accountName defer func() { cli.client.accountKey = oldAK cli.client.accountName = oldAN }() // don't worry, I've already changed mine :) key, err := base64.StdEncoding.DecodeString("zHDHGs7C+Di9pZSDMuarxJJz3xRBzAHBYaobxpLEc7kwTptR/hPEa9j93hIfb2Tbe9IA50MViGmjQ6nUF/OVvA==") if err != nil { c.Fail() } cli.client.accountKey = key cli.client.accountName = "mindgotest" headers := map[string]string{ "Accept-Charset": "UTF-8", "Content-Type": "application/json", "x-ms-date": "Wed, 23 Sep 2015 16:40:05 GMT", "Content-Length": "0", "x-ms-version": "2015-02-21", "Accept": "application/json;odata=nometadata", } url := "https://mindgotest.table.core.windows.net/tquery()" ret, err := cli.client.createSharedKeyLite(url, headers) if err != nil { c.Fail() } c.Assert(ret, chk.Equals, "SharedKeyLite mindgotest:+32DTgsPUgXPo/O7RYaTs0DllA6FTXMj3uK4Qst8y/E=") }
func testMinVer(client *api.Client, t minverTest, c *gc.C) { charmMinVer := version.MustParse(t.charm) jujuVer := version.MustParse(t.juju) cleanup := api.PatchClientFacadeCall(client, func(request string, paramsIn interface{}, response interface{}) error { c.Assert(paramsIn, gc.IsNil) if response, ok := response.(*params.AgentVersionResult); ok { response.Version = jujuVer } else { c.Log("wrong output structure") c.Fail() } return nil }, ) defer cleanup() charmArchive := testcharms.Repo.CharmArchive(c.MkDir(), "dummy") curl := charm.MustParseURL( fmt.Sprintf("local:quantal/%s-%d", charmArchive.Meta().Name, charmArchive.Revision()), ) charmArchive.Meta().MinJujuVersion = charmMinVer _, err := client.AddLocalCharm(curl, charmArchive) if t.ok { if err != nil { c.Errorf("Unexpected non-nil error for jujuver %v, minver %v: %#v", t.juju, t.charm, err) } } else { if err == nil { c.Errorf("Unexpected nil error for jujuver %v, minver %v", t.juju, t.charm) } else if !api.IsMinVersionError(err) { c.Errorf("Wrong error for jujuver %v, minver %v: expected minVersionError, got: %#v", t.juju, t.charm, err) } } }
func (s *IntegrationSuite) SetUpSuite(c *check.C) { if !*integration { c.Skip("integration tests not enabled") return } l, err := net.Listen("tcp", "localhost:42420") if err != nil { c.Log("Can't start Asterisk mock: ", err) c.Fail() } am = &amock{l} go am.start() conn, err := net.Dial("tcp", "localhost:42420") if err != nil { am.stop() c.Log("Can't connect to mock: ", err) c.Fail() } a = NewAsterisk(&conn, nil) a.Login("admin", "admin") sleep(2) }
func (m *GenericTestSuite) TestFail(c *check.C) { c.Fail() }