本文整理汇总了Golang中github.com/juju/juju/worker/uniter/runner/testing.NewRealPaths函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRealPaths函数的具体用法?Golang NewRealPaths怎么用?Golang NewRealPaths使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRealPaths函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRunCommandsEnvStdOutAndErrAndRC
func (s *RunCommandSuite) TestRunCommandsEnvStdOutAndErrAndRC(c *gc.C) {
// TODO(bogdanteleaga): powershell throws another exit status code when
// outputting to stderr using Write-Error. Either find another way to
// output to stderr or change the checks
if runtime.GOOS == "windows" {
c.Skip("bug 1403084: Have to figure out a good way to output to stderr from powershell")
}
ctx, err := s.contextFactory.HookContext(hook.Info{Kind: hooks.ConfigChanged})
c.Assert(err, jc.ErrorIsNil)
paths := runnertesting.NewRealPaths(c)
runner := runner.NewRunner(ctx, paths)
commands := `
echo $JUJU_CHARM_DIR
echo this is standard err >&2
exit 42
`
result, err := runner.RunCommands(commands)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Code, gc.Equals, 42)
c.Assert(strings.TrimRight(string(result.Stdout), "\r\n"), gc.Equals, paths.GetCharmDir())
c.Assert(strings.TrimRight(string(result.Stderr), "\r\n"), gc.Equals, "this is standard err")
c.Assert(ctx.GetProcess(), gc.NotNil)
}
示例2: getHookContext
func (s *HookContextSuite) getHookContext(c *gc.C, uuid string, relid int,
remote string, proxies proxy.Settings) *context.HookContext {
if relid != -1 {
_, found := s.apiRelunits[relid]
c.Assert(found, jc.IsTrue)
}
facade, err := s.st.Uniter()
c.Assert(err, jc.ErrorIsNil)
relctxs := map[int]*context.ContextRelation{}
for relId, relUnit := range s.apiRelunits {
cache := context.NewRelationCache(relUnit.ReadSettings, nil)
relctxs[relId] = context.NewContextRelation(relUnit, cache)
}
env, err := s.State.Environment()
c.Assert(err, jc.ErrorIsNil)
context, err := context.NewHookContext(s.apiUnit, facade, "TestCtx", uuid,
env.Name(), relid, remote, relctxs, apiAddrs,
proxies, false, nil, nil, s.machine.Tag().(names.MachineTag),
runnertesting.NewRealPaths(c))
c.Assert(err, jc.ErrorIsNil)
return context
}
示例3: TestRunHook
func (s *RunHookSuite) TestRunHook(c *gc.C) {
for i, t := range runHookTests {
c.Logf("\ntest %d: %s; perm %v", i, t.summary, t.spec.perm)
ctx, err := s.contextFactory.HookContext(hook.Info{Kind: hooks.ConfigChanged})
c.Assert(err, jc.ErrorIsNil)
paths := runnertesting.NewRealPaths(c)
rnr := runner.NewRunner(ctx, paths)
var hookExists bool
if t.spec.perm != 0 {
spec := t.spec
spec.dir = "hooks"
spec.name = hookName
c.Logf("makeCharm %#v", spec)
makeCharm(c, spec, paths.GetCharmDir())
hookExists = true
}
t0 := time.Now()
err = rnr.RunHook("something-happened")
if t.err == "" && hookExists {
c.Assert(err, jc.ErrorIsNil)
} else if !hookExists {
c.Assert(context.IsMissingHookError(err), jc.IsTrue)
} else {
c.Assert(err, gc.ErrorMatches, t.err)
}
if t.spec.background != "" && time.Now().Sub(t0) > 5*time.Second {
c.Errorf("background process holding up hook execution")
}
}
}
示例4: TestBuiltinMetricNotGeneratedIfNotDefined
func (s *FlushContextSuite) TestBuiltinMetricNotGeneratedIfNotDefined(c *gc.C) {
uuid := utils.MustNewUUID()
paths := runnertesting.NewRealPaths(c)
ctx := s.getMeteredHookContext(c, uuid.String(), -1, "", noProxies, true, s.metricsDefinition("pings"), paths)
reader, err := spool.NewJSONMetricReader(
paths.GetMetricsSpoolDir(),
)
err = ctx.Flush("some badge", nil)
c.Assert(err, jc.ErrorIsNil)
batches, err := reader.Read()
c.Assert(err, jc.ErrorIsNil)
c.Assert(batches, gc.HasLen, 0)
}
示例5: SetUpTest
func (s *ContextFactorySuite) SetUpTest(c *gc.C) {
s.HookContextSuite.SetUpTest(c)
s.paths = runnertesting.NewRealPaths(c)
s.membership = map[int][]string{}
contextFactory, err := context.NewContextFactory(
s.uniter,
s.unit.Tag().(names.UnitTag),
runnertesting.FakeTracker{},
s.getRelationInfos,
s.storage,
s.paths,
)
c.Assert(err, jc.ErrorIsNil)
s.factory = contextFactory
}
示例6: SetUpTest
func (s *RunMockContextSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.paths = runnertesting.NewRealPaths(c)
}
示例7: SetUpTest
func (s *ContextSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.machine = nil
ch := s.AddTestingCharm(c, "wordpress")
s.service = s.AddTestingService(c, "u", ch)
s.unit = s.AddUnit(c, s.service)
storageData0 := names.NewStorageTag("data/0")
s.storage = &runnertesting.StorageContextAccessor{
map[names.StorageTag]*runnertesting.ContextStorage{
storageData0: &runnertesting.ContextStorage{
storageData0,
storage.StorageKindBlock,
"/dev/sdb",
},
},
}
password, err := utils.RandomPassword()
err = s.unit.SetPassword(password)
c.Assert(err, jc.ErrorIsNil)
s.st = s.OpenAPIAs(c, s.unit.Tag(), password)
s.uniter, err = s.st.Uniter()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.uniter, gc.NotNil)
s.apiUnit, err = s.uniter.Unit(s.unit.Tag().(names.UnitTag))
c.Assert(err, jc.ErrorIsNil)
s.paths = runnertesting.NewRealPaths(c)
s.membership = map[int][]string{}
// Note: The unit must always have a charm URL set, because this
// happens as part of the installation process (that happens
// before the initial install hook).
err = s.unit.SetCharmURL(ch.URL())
c.Assert(err, jc.ErrorIsNil)
s.relch = s.AddTestingCharm(c, "mysql")
s.relunits = map[int]*state.RelationUnit{}
s.apiRelunits = map[int]*uniter.RelationUnit{}
s.AddContextRelation(c, "db0")
s.AddContextRelation(c, "db1")
s.contextFactory, err = context.NewContextFactory(
s.uniter,
s.unit.Tag().(names.UnitTag),
runnertesting.FakeTracker{},
s.getRelationInfos,
s.storage,
s.paths,
)
c.Assert(err, jc.ErrorIsNil)
factory, err := runner.NewFactory(
s.uniter,
s.paths,
s.contextFactory,
)
c.Assert(err, jc.ErrorIsNil)
s.factory = factory
}