コード例 #1
0
ファイル: gitolite_test.go プロジェクト: Kunde21/arvados
func (s *GitoliteSuite) SetUpTest(c *check.C) {
	var err error
	s.gitoliteHome, err = ioutil.TempDir("", "arv-git-httpd")
	c.Assert(err, check.Equals, nil)

	runGitolite := func(prog string, args ...string) {
		c.Log(prog, " ", args)
		cmd := exec.Command(prog, args...)
		cmd.Dir = s.gitoliteHome
		cmd.Env = append(os.Environ(), "HOME="+s.gitoliteHome)
		diags, err := cmd.CombinedOutput()
		c.Log(string(diags))
		c.Assert(err, check.Equals, nil)
	}

	runGitolite("gitolite", "setup", "--admin", "root")

	s.tmpRepoRoot = s.gitoliteHome + "/repositories"
	s.Config = &config{
		Addr:       ":0",
		GitCommand: "/usr/share/gitolite3/gitolite-shell",
		Root:       s.tmpRepoRoot,
	}
	s.IntegrationSuite.SetUpTest(c)

	// Install the gitolite hooks in the bare repo we made in
	// (*IntegrationTest)SetUpTest() -- see 2.2.4 at
	// http://gitolite.com/gitolite/gitolite.html
	runGitolite("gitolite", "setup")

	os.Setenv("GITOLITE_HTTP_HOME", s.gitoliteHome)
	os.Setenv("GL_BYPASS_ACCESS_CHECKS", "1")
}
コード例 #2
0
ファイル: args_test.go プロジェクト: wwitzel3/juju-cmd
func (*ArgsSuite) TestFlagsUsage(c *gc.C) {
	for i, test := range []struct {
		message       string
		defaultValue  []string
		args          []string
		expectedValue []string
	}{{
		message: "nil default and no arg",
	}, {
		message:       "default value and not set by args",
		defaultValue:  []string{"foo", "bar"},
		expectedValue: []string{"foo", "bar"},
	}, {
		message:       "no value set by args",
		args:          []string{"--value", "foo,bar"},
		expectedValue: []string{"foo", "bar"},
	}, {
		message:       "default value and set by args",
		defaultValue:  []string{"omg"},
		args:          []string{"--value", "foo,bar"},
		expectedValue: []string{"foo", "bar"},
	}} {
		c.Log(fmt.Sprintf("%v: %s", i, test.message))
		f := gnuflag.NewFlagSet("test", gnuflag.ContinueOnError)
		f.SetOutput(ioutil.Discard)
		var value []string
		f.Var(cmd.NewStringsValue(test.defaultValue, &value), "value", "help")
		err := f.Parse(false, test.args)
		c.Check(err, gc.IsNil)
		c.Check(value, gc.DeepEquals, test.expectedValue)
	}
}
コード例 #3
0
ファイル: action_test.go プロジェクト: makyo/juju
func (s *ActionSuite) TestMergeIds(c *gc.C) {
	var tests = []struct {
		changes  string
		adds     string
		removes  string
		expected string
	}{
		{changes: "", adds: "a0,a1", removes: "", expected: "a0,a1"},
		{changes: "a0,a1", adds: "", removes: "a0", expected: "a1"},
		{changes: "a0,a1", adds: "a2", removes: "a0", expected: "a1,a2"},

		{changes: "", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{changes: "", adds: "a0,a1,a2", removes: "a0,a1,a2", expected: ""},

		{changes: "a0", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{changes: "a1", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{changes: "a2", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},

		{changes: "a3,a4", adds: "a1,a4,a5", removes: "a1,a3", expected: "a4,a5"},
		{changes: "a0,a1,a2", adds: "a1,a4,a5", removes: "a1,a3", expected: "a0,a2,a4,a5"},
	}

	prefix := state.DocID(s.State, "")

	for ix, test := range tests {
		updates := mapify(prefix, test.adds, test.removes)
		changes := sliceify("", test.changes)
		expected := sliceify("", test.expected)

		c.Log(fmt.Sprintf("test number %d %#v", ix, test))
		err := state.WatcherMergeIds(s.State, &changes, updates, state.ActionNotificationIdToActionId)
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(changes, jc.SameContents, expected)
	}
}
コード例 #4
0
ファイル: context_test.go プロジェクト: juju/loggo
func (*ContextSuite) TestNewContextRootLevel(c *gc.C) {
	for i, test := range []struct {
		level    loggo.Level
		expected loggo.Level
	}{{
		level:    loggo.UNSPECIFIED,
		expected: loggo.WARNING,
	}, {
		level:    loggo.DEBUG,
		expected: loggo.DEBUG,
	}, {
		level:    loggo.INFO,
		expected: loggo.INFO,
	}, {
		level:    loggo.WARNING,
		expected: loggo.WARNING,
	}, {
		level:    loggo.ERROR,
		expected: loggo.ERROR,
	}, {
		level:    loggo.CRITICAL,
		expected: loggo.CRITICAL,
	}, {
		level:    loggo.Level(42),
		expected: loggo.WARNING,
	}} {
		c.Log("%d: %s", i, test.level)
		context := loggo.NewContext(test.level)
		cfg := context.Config()
		c.Check(cfg, gc.HasLen, 1)
		value, found := cfg[""]
		c.Check(found, gc.Equals, true)
		c.Check(value, gc.Equals, test.expected)
	}
}
コード例 #5
0
ファイル: client_test.go プロジェクト: kat-co/juju
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: &params.ModelUserInfo{UserName: "******"}},
					{Result: &params.ModelUserInfo{UserName: "******"}},
					{Result: &params.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: "******"},
	})
}
コード例 #6
0
ファイル: args_test.go プロジェクト: wwitzel3/juju-cmd
func (*ArgsSuite) TestString(c *gc.C) {
	for i, test := range []struct {
		message  string
		target   []string
		expected string
	}{{
		message:  "null",
		expected: "",
	}, {
		message:  "empty",
		target:   []string{},
		expected: "",
	}, {
		message:  "single value",
		target:   []string{"foo"},
		expected: "foo",
	}, {
		message:  "multiple values",
		target:   []string{"foo", "bar", "baz"},
		expected: "foo,bar,baz",
	}} {
		c.Log(fmt.Sprintf("%v: %s", i, test.message))
		var temp []string
		value := cmd.NewStringsValue(test.target, &temp)
		c.Assert(value.String(), gc.Equals, test.expected)
	}
}
コード例 #7
0
ファイル: backup_test.go プロジェクト: Pankov404/juju
func (s *backupsSuite) TestInvalidHTTPMethods(c *gc.C) {
	url := s.backupURL(c)
	for _, method := range []string{"POST", "DELETE", "OPTIONS"} {
		c.Log("testing HTTP method: " + method)
		s.checkInvalidMethod(c, method, url)
	}
}
コード例 #8
0
ファイル: machine_test.go プロジェクト: bac/juju
func (s *MachineSuite) assertAgentSetsToolsVersion(c *gc.C, job state.MachineJob) {
	vers := version.Binary{
		Number: jujuversion.Current,
		Arch:   arch.HostArch(),
		Series: series.HostSeries(),
	}
	vers.Minor++
	m, _, _ := s.primeAgentVersion(c, vers, job)
	a := s.newAgent(c, m)
	go func() { c.Check(a.Run(nil), jc.ErrorIsNil) }()
	defer func() { c.Check(a.Stop(), jc.ErrorIsNil) }()

	timeout := time.After(coretesting.LongWait)
	for done := false; !done; {
		select {
		case <-timeout:
			c.Fatalf("timeout while waiting for agent version to be set")
		case <-time.After(coretesting.ShortWait):
			c.Log("Refreshing")
			err := m.Refresh()
			c.Assert(err, jc.ErrorIsNil)
			c.Log("Fetching agent tools")
			agentTools, err := m.AgentTools()
			c.Assert(err, jc.ErrorIsNil)
			c.Logf("(%v vs. %v)", agentTools.Version, jujuversion.Current)
			if agentTools.Version.Minor != jujuversion.Current.Minor {
				continue
			}
			c.Assert(agentTools.Version.Number, gc.DeepEquals, jujuversion.Current)
			done = true
		}
	}
}
コード例 #9
0
ファイル: run_test.go プロジェクト: pmatulis/juju
func (*RunSuite) TestTimeoutArgParsing(c *gc.C) {
	for i, test := range []struct {
		message  string
		args     []string
		errMatch string
		timeout  time.Duration
	}{{
		message: "default time",
		args:    []string{"--all", "sudo reboot"},
		timeout: 5 * time.Minute,
	}, {
		message:  "invalid time",
		args:     []string{"--timeout=foo", "--all", "sudo reboot"},
		errMatch: `invalid value "foo" for flag --timeout: time: invalid duration foo`,
	}, {
		message: "two hours",
		args:    []string{"--timeout=2h", "--all", "sudo reboot"},
		timeout: 2 * time.Hour,
	}, {
		message: "3 minutes 30 seconds",
		args:    []string{"--timeout=3m30s", "--all", "sudo reboot"},
		timeout: (3 * time.Minute) + (30 * time.Second),
	}} {
		c.Log(fmt.Sprintf("%v: %s", i, test.message))
		cmd := &runCommand{}
		runCmd := modelcmd.Wrap(cmd)
		testing.TestInit(c, runCmd, test.args, test.errMatch)
		if test.errMatch == "" {
			c.Check(cmd.timeout, gc.Equals, test.timeout)
		}
	}
}
コード例 #10
0
ファイル: runner.go プロジェクト: cmars/conflux
// Test full node sync.
func (s *ReconSuite) TestFullSync(c *gc.C) {
	ptree1, cleanup, err := s.Factory()
	c.Assert(err, gc.IsNil)
	defer cleanup()

	ptree2, cleanup, err := s.Factory()
	c.Assert(err, gc.IsNil)
	defer cleanup()

	ptree1.Insert(cf.Zi(cf.P_SKS, 65537))
	ptree1.Insert(cf.Zi(cf.P_SKS, 65539))
	root, _ := ptree1.Root()
	c.Log("peer1:", recon.MustElements(root))

	ptree2.Insert(cf.Zi(cf.P_SKS, 65537))
	ptree2.Insert(cf.Zi(cf.P_SKS, 65541))
	root, _ = ptree2.Root()
	c.Log("peer2:", recon.MustElements(root))

	port1, port2 := portPair(c)
	peer1 := s.newPeer(port1, port2, recon.PeerModeGossipOnly, ptree1)
	peer2 := s.newPeer(port2, port1, recon.PeerModeServeOnly, ptree2)

	err = s.pollRootConvergence(c, peer1, peer2, ptree1, ptree2)
	c.Assert(err, gc.IsNil)
}
コード例 #11
0
ファイル: conn_test.go プロジェクト: kat-co/juju
func (cs *ConnSuite) SetUpTest(c *gc.C) {
	c.Log("SetUpTest")

	cs.policy = statetesting.MockPolicy{
		GetStorageProviderRegistry: func() (storage.ProviderRegistry, error) {
			return dummy.StorageProviders(), nil
		},
	}
	cs.StateSuite.NewPolicy = func(*state.State) state.Policy {
		return &cs.policy
	}

	cs.StateSuite.SetUpTest(c)

	cs.modelTag = cs.State.ModelTag()

	jujuDB := cs.MgoSuite.Session.DB("juju")
	cs.annotations = jujuDB.C("annotations")
	cs.charms = jujuDB.C("charms")
	cs.machines = jujuDB.C("machines")
	cs.instanceData = jujuDB.C("instanceData")
	cs.relations = jujuDB.C("relations")
	cs.services = jujuDB.C("applications")
	cs.units = jujuDB.C("units")
	cs.controllers = jujuDB.C("controllers")

	c.Log("SetUpTest done")
}
コード例 #12
0
ファイル: base.go プロジェクト: ktsakalozos/juju
func diffStrings(c *gc.C, value, expected string) {
	// If only Go had a diff library.
	vlines := strings.Split(value, "\n")
	elines := strings.Split(expected, "\n")
	vsize := len(vlines)
	esize := len(elines)

	if vsize < 2 || esize < 2 {
		return
	}

	smaller := elines
	if vsize < esize {
		smaller = vlines
	}

	for i := range smaller {
		vline := vlines[i]
		eline := elines[i]
		if vline != eline {
			c.Logf("first mismatched line (%d/%d):", i, len(smaller))
			c.Log("expected: " + eline)
			c.Log("got:      " + vline)
			break
		}
	}
}
コード例 #13
0
ファイル: labs_test.go プロジェクト: peter1000/oanda
func (ts *TestLabsSuite) TestLabsAutochartistPattern(c *check.C) {
	p, err := ts.c.AutochartistPattern()
	c.Assert(err, check.IsNil)
	c.Log(p)
	c.Assert(p.Provider, check.Equals, "autochartist")
	c.Assert(len(p.Signals) > 0, check.Equals, true)
}
コード例 #14
0
ファイル: labs_test.go プロジェクト: peter1000/oanda
func (ts *TestLabsSuite) TestLabsCommitmentsOfTraders(c *check.C) {
	instrument := "eur_usd"
	cot, err := ts.c.CommitmentsOfTraders(instrument)
	c.Assert(err, check.IsNil)
	c.Log(cot)
	c.Assert(len(cot) > 0, check.Equals, true)
}
コード例 #15
0
ファイル: client_test.go プロジェクト: ktsakalozos/juju
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 := &params.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")
}
コード例 #16
0
ファイル: server_test.go プロジェクト: WangZhenfei/arvados
func (s *IntegrationSuite) runGit(c *check.C, token, gitCmd, repo string, args ...string) error {
	cwd, err := os.Getwd()
	c.Assert(err, check.Equals, nil)
	defer os.Chdir(cwd)
	os.Chdir(s.tmpWorkdir)

	gitargs := append([]string{
		gitCmd, "http://" + s.testServer.Addr + "/" + repo,
	}, args...)
	cmd := exec.Command("git", gitargs...)
	cmd.Env = append(os.Environ(), "ARVADOS_API_TOKEN="+token)
	w, err := cmd.StdinPipe()
	c.Assert(err, check.Equals, nil)
	w.Close()
	output, err := cmd.CombinedOutput()
	c.Log("git ", gitargs, " => ", err)
	c.Log(string(output))
	if err != nil && len(output) > 0 {
		// If messages appeared on stderr, they are more
		// helpful than the err returned by CombinedOutput().
		//
		// Easier to match error strings without newlines:
		err = errors.New(strings.Replace(string(output), "\n", " // ", -1))
	}
	return err
}
コード例 #17
0
ファイル: server_test.go プロジェクト: Kunde21/arvados
// Make a bare arvados repo at {tmpRepoRoot}/arvados.git
func (s *GitSuite) makeArvadosRepo(c *check.C) {
	msg, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git").CombinedOutput()
	c.Log(string(msg))
	c.Assert(err, check.Equals, nil)
	msg, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git", "fetch", "../../.git", "HEAD:master").CombinedOutput()
	c.Log(string(msg))
	c.Assert(err, check.Equals, nil)
}
コード例 #18
0
ファイル: labs_test.go プロジェクト: peter1000/oanda
func (ts *TestLabsSuite) TestLabsOrderBooks(c *check.C) {
	instrument, period := "eur_usd", 6*oanda.Hour
	obs, err := ts.c.OrderBooks(instrument, period)
	c.Assert(err, check.IsNil)
	c.Log(obs)
	c.Assert(len(obs) > 1, check.Equals, true)
	c.Assert(obs[0].Timestamp.After(obs[1].Timestamp), check.Equals, true)
}
コード例 #19
0
ファイル: labs_test.go プロジェクト: peter1000/oanda
func (ts *TestLabsSuite) TestLabsSpreads(c *check.C) {
	instrument := "eur_usd"
	spreads, err := ts.c.Spreads(instrument, oanda.Day, true)
	c.Assert(err, check.IsNil)
	c.Log(spreads)
	c.Assert(len(spreads.Max) > 0, check.Equals, true)
	c.Assert(len(spreads.Avg) > 0, check.Equals, true)
	c.Assert(len(spreads.Min) > 0, check.Equals, true)
}
コード例 #20
0
ファイル: leadership_test.go プロジェクト: frankban/juju-tmp
func (s *uniterLeadershipSuite) TearDownTest(c *gc.C) {
	c.Log("Stopping machine agent...")
	err := s.machineAgent.Stop()
	c.Check(err, jc.ErrorIsNil)
	if s.apiState != nil {
		err := s.apiState.Close()
		c.Assert(err, jc.ErrorIsNil)
	}
	s.AgentSuite.TearDownTest(c)
}
コード例 #21
0
ファイル: labs_test.go プロジェクト: peter1000/oanda
func (ts *TestLabsSuite) TestLabsPositionRatios(c *check.C) {
	instrument := "eur_usd"
	ratios, err := ts.c.PositionRatios(instrument, oanda.Year)
	c.Assert(err, check.IsNil)
	c.Log(ratios)
	instrument = strings.ToUpper(instrument)
	c.Assert(ratios.Instrument, check.Equals, instrument)
	c.Assert(ratios.DisplayName, check.Equals, strings.Replace(instrument, "_", "/", -1))
	c.Assert(len(ratios.Ratios) > 0, check.Equals, true)
}
コード例 #22
0
ファイル: main_test.go プロジェクト: Pankov404/juju
func (s *JujuCMainSuite) TestArgs(c *gc.C) {
	if runtime.GOOS == "windows" {
		c.Skip("issue 1403084: test panics on CryptAcquireContext on windows")
	}
	for _, t := range argsTests {
		c.Log(t.args)
		output := run(c, s.sockPath, "bill", t.code, nil, t.args...)
		c.Assert(output, gc.Equals, t.output)
	}
}
コード例 #23
0
ファイル: upgrade_mongo_test.go プロジェクト: kat-co/juju
func (s *UpgradeMongoSuite) TestMongoRestoreRetries(c *gc.C) {
	command := fakeRunCommand{}
	callArgs := retryCallArgs()
	err := mongoRestoreCall(command.runCommandFail, "/fake/tmp/dir", "/fake/mongo/path", "", "aMigrationName", []string{}, 1234, false, 0, callArgs)
	c.Assert(err, gc.ErrorMatches, "cannot restore dbs got: this failed: attempt count exceeded: a generic error")
	c.Assert(command.ranCommands, gc.HasLen, 60)
	for i := range command.ranCommands {
		c.Log(fmt.Sprintf("Checking attempt %d", i))
		c.Assert(command.ranCommands[i], gc.DeepEquals, []string{"/fake/mongo/path/mongorestore", "--ssl", "--port", "1234", "--host", "localhost", "/fake/tmp/dir/migrateToaMigrationNamedump"})
	}
}
コード例 #24
0
ファイル: file_test.go プロジェクト: scale-it/checkers
func (s *FileSuite) TestIsSymlink(c *gc.C) {
	file, err := ioutil.TempFile(c.MkDir(), "")
	c.Assert(err, gc.IsNil)
	c.Log(file.Name())
	c.Log(filepath.Dir(file.Name()))
	symlinkPath := filepath.Join(filepath.Dir(file.Name()), "a-symlink")
	err = os.Symlink(file.Name(), symlinkPath)
	c.Assert(err, gc.IsNil)

	c.Assert(symlinkPath, IsSymlink)
}
コード例 #25
0
ファイル: config_test.go プロジェクト: AlexisBruemmer/juju
func newLocalClient(c *gc.C) *lxdclient.Client {
	client, err := lxdclient.Connect(lxdclient.Config{
		Namespace: "my-ns",
		Remote:    lxdclient.Local,
	})
	if err != nil {
		c.Log(err)
		return nil
	}
	return client
}
コード例 #26
0
ファイル: io_test.go プロジェクト: squeed/openpgp
func (s *SamplePacketSuite) TestDeduplicate(c *gc.C) {
	f := testing.MustInput("d7346e26.asc")
	defer f.Close()
	block, err := armor.Decode(f)
	if err != nil {
		c.Fatal(err)
	}

	// Parse keyring, duplicate all packet types except primary pubkey.
	kr := &OpaqueKeyring{}
	for opkr := range ReadOpaqueKeyrings(block.Body) {
		c.Assert(opkr.Error, gc.IsNil)
		for _, op := range opkr.Packets {
			kr.Packets = append(kr.Packets, op)
			switch op.Tag {
			case 2:
				kr.Packets = append(kr.Packets, op)
				fallthrough
			case 13, 14, 17:
				kr.Packets = append(kr.Packets, op)
			}
		}
	}
	key, err := kr.Parse()
	c.Assert(err, gc.IsNil)

	n := 0
	for _, node := range key.contents() {
		c.Logf("%s", node.uuid())
		n++
	}

	c.Log()
	err = CollectDuplicates(key)
	c.Assert(err, gc.IsNil)

	n2 := 0
	for _, node := range key.contents() {
		c.Logf("%s %d", node.uuid(), node.packet().Count)
		n2++
		switch node.packet().Tag {
		case 2:
			c.Check(node.packet().Count, gc.Equals, 2)
		case 13, 14, 17:
			c.Check(node.packet().Count, gc.Equals, 1)
		case 6:
			c.Check(node.packet().Count, gc.Equals, 0)
		default:
			c.Fatal("should not happen")
		}
	}
	c.Assert(n2 < n, gc.Equals, true)
}
コード例 #27
0
ファイル: leadership_test.go プロジェクト: frankban/juju-tmp
func (s *leadershipSuite) TearDownTest(c *gc.C) {
	c.Log("Stopping machine agent...")
	err := s.machineAgent.Stop()
	c.Assert(err, jc.ErrorIsNil)
	os.RemoveAll(filepath.Join(s.DataDir(), "tools"))
	if s.apiState != nil {
		err := s.apiState.Close()
		c.Assert(err, jc.ErrorIsNil)
	}

	s.AgentSuite.TearDownTest(c)
}
コード例 #28
0
ファイル: run_test.go プロジェクト: pmatulis/juju
func (s *RunSuite) TestSingleResponse(c *gc.C) {
	mock := s.setupMockAPI()
	mock.setMachinesAlive("0")
	mockResponse := mockResponse{
		stdout:    "stdout\n",
		stderr:    "stderr\n",
		code:      42,
		machineId: "0",
	}
	mock.setResponse("0", mockResponse)
	unformatted := ConvertRunResults([]params.RunResult{
		makeRunResult(mockResponse)})
	yamlFormatted, err := cmd.FormatYaml(unformatted)
	c.Assert(err, jc.ErrorIsNil)
	jsonFormatted, err := cmd.FormatJson(unformatted)
	c.Assert(err, jc.ErrorIsNil)

	for i, test := range []struct {
		message    string
		format     string
		stdout     string
		stderr     string
		errorMatch string
	}{{
		message:    "smart (default)",
		stdout:     "stdout\n",
		stderr:     "stderr\n",
		errorMatch: "subprocess encountered error code 42",
	}, {
		message: "yaml output",
		format:  "yaml",
		stdout:  string(yamlFormatted) + "\n",
	}, {
		message: "json output",
		format:  "json",
		stdout:  string(jsonFormatted) + "\n",
	}} {
		c.Log(fmt.Sprintf("%v: %s", i, test.message))
		args := []string{}
		if test.format != "" {
			args = append(args, "--format", test.format)
		}
		args = append(args, "--all", "ignored")
		context, err := testing.RunCommand(c, newRunCommand(), args...)
		if test.errorMatch != "" {
			c.Check(err, gc.ErrorMatches, test.errorMatch)
		} else {
			c.Check(err, jc.ErrorIsNil)
		}
		c.Check(testing.Stdout(context), gc.Equals, test.stdout)
		c.Check(testing.Stderr(context), gc.Equals, test.stderr)
	}
}
コード例 #29
0
ファイル: metadataplugin_test.go プロジェクト: exekias/juju
func getHelpCommandNames(c *gc.C) []string {
	out := badrun(c, 0, "--help")
	c.Log(out)
	var names []string
	commandHelpStrings := strings.SplitAfter(out, "commands:")
	c.Assert(len(commandHelpStrings), gc.Equals, 2)
	commandHelp := strings.TrimSpace(commandHelpStrings[1])
	for _, line := range strings.Split(commandHelp, "\n") {
		names = append(names, strings.TrimSpace(strings.Split(line, " - ")[0]))
	}
	return names
}
コード例 #30
0
ファイル: keyvalues_test.go プロジェクト: juju/utils
func (keyValuesSuite) TestMapParsing(c *gc.C) {
	for i, t := range testCases {
		c.Log("test %d: %s", i, t.about)
		result, err := keyvalues.Parse(t.input, t.allowEmptyVal)
		c.Check(result, gc.DeepEquals, t.output)
		if t.error == "" {
			c.Check(err, gc.IsNil)
		} else {
			c.Check(err, gc.ErrorMatches, t.error)
		}
	}
}