本文整理汇总了Golang中github.com/square/p2/pkg/util.From函数的典型用法代码示例。如果您正苦于以下问题:Golang From函数的具体用法?Golang From怎么用?Golang From使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了From函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: FakeHoistLaunchableForDir
func FakeHoistLaunchableForDir(dirName string) (*Launchable, *runit.ServiceBuilder) {
tempDir, _ := ioutil.TempDir("", "fakeenv")
launchableInstallDir := util.From(runtime.Caller(0)).ExpandPath(dirName)
launchable := &Launchable{
Location: "testLaunchable.tar.gz",
Id: "testPod__testLaunchable",
RunAs: "testPod",
PodEnvDir: tempDir,
Fetcher: uri.DefaultFetcher,
RootDir: launchableInstallDir,
P2Exec: util.From(runtime.Caller(0)).ExpandPath("fake_p2-exec"),
}
curUser, err := user.Current()
if err == nil {
launchable.RunAs = curUser.Username
}
sbTemp, _ := ioutil.TempDir("", "fakesvdir")
sb := &runit.ServiceBuilder{
RunitRoot: sbTemp,
}
executables, _ := launchable.Executables(sb)
for _, exe := range executables {
os.MkdirAll(exe.Service.Path, 0644)
}
return launchable, sb
}
开发者ID:tomzhang,项目名称:p2,代码行数:31,代码来源:test_helper.go
示例2: signBuild
func signBuild(artifactPath string) error {
sigLoc := fmt.Sprintf("%s.sig", artifactPath)
return exec.Command("gpg", "--no-default-keyring",
"--keyring", util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"),
"--secret-keyring", util.From(runtime.Caller(0)).ExpandPath("secring.gpg"),
"-u", "p2universe",
"--out", sigLoc,
"--detach-sign", artifactPath).Run()
}
开发者ID:rudle,项目名称:p2,代码行数:9,代码来源:check.go
示例3: signManifest
func signManifest(manifestPath string, workdir string) (string, error) {
signedManifestPath := fmt.Sprintf("%s.asc", manifestPath)
return signedManifestPath,
exec.Command("gpg", "--no-default-keyring",
"--keyring", util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"),
"--secret-keyring", util.From(runtime.Caller(0)).ExpandPath("secring.gpg"),
"-u", "p2universe",
"--output", signedManifestPath,
"--clearsign", manifestPath).Run()
}
开发者ID:robertabbott,项目名称:p2,代码行数:10,代码来源:check.go
示例4: signBuild
func signBuild(artifactPath string) error {
sigLoc := fmt.Sprintf("%s.sig", artifactPath)
output, err := exec.Command("gpg", "--no-default-keyring",
"--keyring", util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"),
"--secret-keyring", util.From(runtime.Caller(0)).ExpandPath("secring.gpg"),
"-u", "p2universe",
"--out", sigLoc,
"--detach-sign", artifactPath).CombinedOutput()
if err != nil {
fmt.Println(string(output))
return err
}
return nil
}
开发者ID:petertseng,项目名称:p2,代码行数:15,代码来源:check.go
示例5: FakeServiceBuilder
// FakeServiceBuilder constructs a testServiceBuilder for use in unit tests. It is the
// caller's responsibility to always call Cleanup() on the return value to ensure that
// file system changes are removed when this test ends.
func FakeServiceBuilder() (s *testServiceBuilder) {
root, err := ioutil.TempDir("", "runit_test")
if err != nil {
panic(err)
}
defer func() {
// If the method exits abnormally, try to clean up the file system.
if s == nil {
os.RemoveAll(root)
}
}()
config := filepath.Join(root, "config")
mustMkdirAll(config)
staging := filepath.Join(root, "staging")
mustMkdirAll(staging)
install := filepath.Join(root, "service")
mustMkdirAll(install)
bin := util.From(runtime.Caller(0)).ExpandPath("fake_servicebuilder")
return &testServiceBuilder{
root: root,
ServiceBuilder: ServiceBuilder{
ConfigRoot: config,
StagingRoot: staging,
RunitRoot: install,
Bin: bin,
testingNoChown: true,
},
}
}
开发者ID:tomzhang,项目名称:p2,代码行数:34,代码来源:test_helper.go
示例6: postHelloManifest
func postHelloManifest(dir string) error {
hello := fmt.Sprintf("file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-hello_def456.tar.gz"))
manifest := &pods.Manifest{}
manifest.Id = "hello"
stanza := pods.LaunchableStanza{
LaunchableId: "hello",
LaunchableType: "hoist",
Location: hello,
}
manifest.LaunchableStanzas = map[string]pods.LaunchableStanza{
"hello": stanza,
}
manifestPath := path.Join(dir, "hello.yaml")
f, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
err = manifest.Write(f)
if err != nil {
return err
}
f.Close()
manifestPath, err = signManifest(manifestPath, dir)
if err != nil {
return err
}
return exec.Command("p2-schedule", manifestPath).Run()
}
开发者ID:robertabbott,项目名称:p2,代码行数:32,代码来源:check.go
示例7: postHelloManifest
func postHelloManifest(dir string) error {
hello := fmt.Sprintf("file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-hello_def456.tar.gz"))
builder := pods.NewManifestBuilder()
builder.SetID("hello")
builder.SetStatusPort(43770)
stanzas := map[string]pods.LaunchableStanza{
"hello": {
LaunchableId: "hello",
LaunchableType: "hoist",
Location: hello,
},
}
builder.SetLaunchables(stanzas)
manifest := builder.GetManifest()
manifestPath := path.Join(dir, "hello.yaml")
f, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
err = manifest.Write(f)
if err != nil {
return err
}
f.Close()
manifestPath, err = signManifest(manifestPath, dir)
if err != nil {
return err
}
return exec.Command("p2-schedule", manifestPath).Run()
}
开发者ID:tomzhang,项目名称:p2,代码行数:34,代码来源:check.go
示例8: getConsulManifest
func getConsulManifest(dir string) (string, error) {
consulTar := fmt.Sprintf(
"file://%s",
util.From(runtime.Caller(0)).ExpandPath("../hoisted-consul_052.tar.gz"),
)
builder := pods.NewManifestBuilder()
builder.SetID("consul")
stanzas := map[string]pods.LaunchableStanza{
"consul": {
LaunchableId: "consul",
LaunchableType: "hoist",
Location: consulTar,
},
}
builder.SetLaunchables(stanzas)
manifest := builder.GetManifest()
consulPath := path.Join(dir, "consul.yaml")
f, err := os.OpenFile(consulPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return "", err
}
defer f.Close()
err = manifest.Write(f)
if err != nil {
return "", err
}
return consulPath, f.Close()
}
开发者ID:tomzhang,项目名称:p2,代码行数:30,代码来源:check.go
示例9: writeHelloManifest
// Writes a pod manifest for the hello pod at with the specified name in the
// specified dir, configured to run on the specified port. Returns the path to
// the signed manifest
func writeHelloManifest(dir string, manifestName string, port int) (string, error) {
hello := fmt.Sprintf("file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-hello_def456.tar.gz"))
builder := manifest.NewBuilder()
builder.SetID("hello")
builder.SetStatusPort(port)
builder.SetStatusHTTP(true)
stanzas := map[launch.LaunchableID]launch.LaunchableStanza{
"hello": {
LaunchableType: "hoist",
Location: hello,
},
}
builder.SetLaunchables(stanzas)
builder.SetConfig(map[interface{}]interface{}{
"port": port,
})
manifest := builder.GetManifest()
manifestPath := filepath.Join(dir, manifestName)
f, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return "", err
}
defer f.Close()
err = manifest.Write(f)
if err != nil {
return "", err
}
return signManifest(manifestPath, dir)
}
开发者ID:petertseng,项目名称:p2,代码行数:34,代码来源:check.go
示例10: testManifest
func testManifest(t *testing.T) pods.Manifest {
manifestPath := util.From(runtime.Caller(0)).ExpandPath("test_manifest.yaml")
manifest, err := pods.ManifestFromPath(manifestPath)
if err != nil {
t.Fatal("No test manifest found, failing\n")
}
return manifest
}
开发者ID:tomzhang,项目名称:p2,代码行数:8,代码来源:orchestrate_test.go
示例11: testHookListener
func testHookListener(t *testing.T) (HookListener, string, <-chan struct{}) {
hookPrefix := kp.HOOK_TREE
destDir, _ := ioutil.TempDir("", "pods")
defer os.RemoveAll(destDir)
execDir, err := ioutil.TempDir("", "exec")
defer os.RemoveAll(execDir)
Assert(t).IsNil(err, "should not have erred creating a tempdir")
current, err := user.Current()
Assert(t).IsNil(err, "test setup: could not get the current user")
builder := manifest.NewBuilder()
builder.SetID("users")
builder.SetRunAsUser(current.Username)
builder.SetLaunchables(map[launch.LaunchableID]launch.LaunchableStanza{
"create": {
Location: util.From(runtime.Caller(0)).ExpandPath("hoisted-hello_def456.tar.gz"),
LaunchableType: "hoist",
LaunchableId: "create",
},
})
podManifest := builder.GetManifest()
manifestBytes, err := podManifest.Marshal()
Assert(t).IsNil(err, "manifest bytes error should have been nil")
fakeSigner, err := openpgp.NewEntity("p2", "p2-test", "[email protected]", nil)
Assert(t).IsNil(err, "NewEntity error should have been nil")
var buf bytes.Buffer
sigWriter, err := clearsign.Encode(&buf, fakeSigner.PrivateKey, nil)
Assert(t).IsNil(err, "clearsign encode error should have been nil")
sigWriter.Write(manifestBytes)
sigWriter.Close()
podManifest, err = manifest.FromBytes(buf.Bytes())
Assert(t).IsNil(err, "should have generated manifest from signed bytes")
fakeIntent := fakeStoreWithManifests(kp.ManifestResult{
Manifest: podManifest,
})
hookFactory := pods.NewHookFactory(destDir, "testNode")
listener := HookListener{
Intent: fakeIntent,
HookPrefix: hookPrefix,
ExecDir: execDir,
HookFactory: hookFactory,
Logger: logging.DefaultLogger,
authPolicy: auth.FixedKeyringPolicy{openpgp.EntityList{fakeSigner}, nil},
artifactVerifier: auth.NopVerifier(),
artifactRegistry: artifact.NewRegistry(nil, uri.DefaultFetcher, osversion.DefaultDetector),
}
return listener, destDir, fakeIntent.quit
}
开发者ID:drcapulet,项目名称:p2,代码行数:56,代码来源:listener_test.go
示例12: generatePreparerPod
func generatePreparerPod(workdir string) (string, error) {
// build the artifact from HEAD
err := exec.Command("go", "build", "github.com/square/p2/bin/p2-preparer").Run()
if err != nil {
return "", util.Errorf("Couldn't build preparer: %s", err)
}
wd, _ := os.Getwd()
hostname, err := os.Hostname()
if err != nil {
return "", util.Errorf("Couldn't get hostname: %s", err)
}
// the test number forces the pod manifest to change every test run.
testNumber := fmt.Sprintf("test=%d", rand.Intn(2000000000))
cmd := exec.Command("p2-bin2pod", "--work-dir", workdir, "--id", "p2-preparer", "--config", fmt.Sprintf("node_name=%s", hostname), "--config", testNumber, wd+"/p2-preparer")
manifestPath, err := executeBin2Pod(cmd)
if err != nil {
return "", err
}
manifest, err := pods.ManifestFromPath(manifestPath)
if err != nil {
return "", err
}
builder := manifest.GetBuilder()
builder.SetID("p2-preparer")
builder.SetConfig(map[interface{}]interface{}{
"preparer": map[interface{}]interface{}{
"auth": map[string]string{
"type": "keyring",
"keyring": util.From(runtime.Caller(0)).ExpandPath("pubring.gpg"),
},
"ca_file": filepath.Join(certpath, "cert.pem"),
"cert_file": filepath.Join(certpath, "cert.pem"),
"key_file": filepath.Join(certpath, "key.pem"),
"status_port": preparerStatusPort,
},
})
builder.SetRunAsUser("root")
builder.SetStatusPort(preparerStatusPort)
builder.SetStatusHTTP(true)
manifest = builder.GetManifest()
manifestBytes, err := manifest.Marshal()
if err != nil {
return "", err
}
err = ioutil.WriteFile(manifestPath, manifestBytes, 0644)
if err != nil {
return "", err
}
return manifestPath, err
}
开发者ID:tomzhang,项目名称:p2,代码行数:55,代码来源:check.go
示例13: TestInstall
func TestInstall(t *testing.T) {
fetcher := uri.NewLoggedFetcher(nil)
testContext := util.From(runtime.Caller(0))
currentUser, err := user.Current()
Assert(t).IsNil(err, "test setup: couldn't get current user")
testLocation := testContext.ExpandPath("hoisted-hello_3c021aff048ca8117593f9c71e03b87cf72fd440.tar.gz")
launchables := map[launch.LaunchableID]launch.LaunchableStanza{
"hello": {
LaunchableId: "hello",
Location: testLocation,
LaunchableType: "hoist",
},
}
builder := manifest.NewBuilder()
builder.SetID("hello")
builder.SetLaunchables(launchables)
builder.SetRunAsUser(currentUser.Username)
manifest := builder.GetManifest()
testPodDir, err := ioutil.TempDir("", "testPodDir")
Assert(t).IsNil(err, "Got an unexpected error creating a temp directory")
defer os.RemoveAll(testPodDir)
pod := Pod{
Id: "testPod",
home: testPodDir,
logger: Log.SubLogger(logrus.Fields{"pod": "testPod"}),
Fetcher: fetcher,
}
err = pod.Install(manifest, auth.NopVerifier(), artifact.NewRegistry(nil, uri.DefaultFetcher, osversion.DefaultDetector))
Assert(t).IsNil(err, "there should not have been an error when installing")
Assert(t).AreEqual(
fetcher.SrcUri.String(),
testLocation,
"The correct url wasn't set for the curl library",
)
hoistedHelloUnpacked := filepath.Join(testPodDir, "hello", "installs", "hello_3c021aff048ca8117593f9c71e03b87cf72fd440")
if info, err := os.Stat(hoistedHelloUnpacked); err != nil || !info.IsDir() {
t.Fatalf("Expected %s to be the unpacked artifact location", hoistedHelloUnpacked)
}
helloLaunch := filepath.Join(hoistedHelloUnpacked, "bin", "launch")
if info, err := os.Stat(helloLaunch); err != nil || info.IsDir() {
t.Fatalf("Expected %s to be a the launch script for hello", helloLaunch)
}
}
开发者ID:rudle,项目名称:p2,代码行数:52,代码来源:pod_test.go
示例14: TestURIWithNoProtocolTreatedLikeLocalPath
func TestURIWithNoProtocolTreatedLikeLocalPath(t *testing.T) {
tempdir, err := ioutil.TempDir("", "cp-dest")
Assert(t).IsNil(err, "Couldn't create temp dir")
defer os.RemoveAll(tempdir)
thisFile := util.From(runtime.Caller(0)).Filename
copied := filepath.Join(tempdir, "copied")
err = URICopy(thisFile, copied)
Assert(t).IsNil(err, "The file should have been copied")
copiedContents, err := ioutil.ReadFile(copied)
thisContents, err := ioutil.ReadFile(thisFile)
Assert(t).IsNil(err, "The original file could not be read")
Assert(t).AreEqual(string(thisContents), string(copiedContents), "The contents of the files do not match")
}
开发者ID:tomzhang,项目名称:p2,代码行数:13,代码来源:uri_test.go
示例15: createHelloReplicationController
func createHelloReplicationController(dir string) (fields.ID, error) {
hello := fmt.Sprintf("file://%s", util.From(runtime.Caller(0)).ExpandPath("../hoisted-hello_def456.tar.gz"))
builder := manifest.NewBuilder()
builder.SetID("hello")
builder.SetStatusPort(43770)
stanzas := map[launch.LaunchableID]launch.LaunchableStanza{
"hello": {
LaunchableId: "hello",
LaunchableType: "hoist",
Location: hello,
},
}
builder.SetLaunchables(stanzas)
manifest := builder.GetManifest()
manifestPath := path.Join(dir, "hello.yaml")
f, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return fields.ID(""), err
}
defer f.Close()
err = manifest.Write(f)
if err != nil {
return fields.ID(""), err
}
f.Close()
manifestPath, err = signManifest(manifestPath, dir)
if err != nil {
return fields.ID(""), err
}
cmd := exec.Command("p2-rctl", "--log-json", "create", "--manifest", manifestPath, "--node-selector", "test=yes")
out := bytes.Buffer{}
cmd.Stdout = &out
cmd.Stderr = &out
err = cmd.Run()
if err != nil {
return fields.ID(""), fmt.Errorf("Couldn't create replication controller for hello: %s %s", out.String(), err)
}
var rctlOut struct {
ID string `json:"id"`
}
err = json.Unmarshal(out.Bytes(), &rctlOut)
if err != nil {
return fields.ID(""), fmt.Errorf("Couldn't read RC ID out of p2-rctl invocation result: %v", err)
}
return fields.ID(rctlOut.ID), exec.Command("p2-rctl", "set-replicas", rctlOut.ID, "1").Run()
}
开发者ID:rudle,项目名称:p2,代码行数:51,代码来源:check.go
示例16: buildTestFileTree
func buildTestFileTree(t *testing.T, files []testFile) string {
tempDir, err := ioutil.TempDir("", "test-artifact-verifier")
if err != nil {
t.Fatalf("Could not make tempdir for verification: %v", err)
}
artifactDir := util.From(runtime.Caller(0)).ExpandPath(testdata)
for _, file := range files {
err = os.Link(filepath.Join(artifactDir, string(file)), filepath.Join(tempDir, string(file)))
if err != nil {
t.Fatal(err)
}
}
return tempDir
}
开发者ID:petertseng,项目名称:p2,代码行数:14,代码来源:artifact_verifier_test.go
示例17: TestLoadConfigWillMarshalYaml
func TestLoadConfigWillMarshalYaml(t *testing.T) {
configPath := util.From(runtime.Caller(0)).ExpandPath("test_preparer_config.yaml")
preparerConfig, err := LoadPreparerConfig(configPath)
Assert(t).IsNil(err, "should have read config correctly")
Assert(t).AreEqual("foohost", preparerConfig.NodeName, "did not read the node name correctly")
Assert(t).AreEqual("0.0.0.0", preparerConfig.ConsulAddress, "did not read the consul address correctly")
Assert(t).AreEqual("/etc/p2/hooks", preparerConfig.HooksDirectory, "did not read the hooks directory correctly")
Assert(t).AreEqual("/etc/p2.keyring", preparerConfig.Auth["keyring"], "did not read the keyring path correctly")
Assert(t).AreEqual(1, len(preparerConfig.ExtraLogDestinations), "should have picked up 1 log destination")
destination := preparerConfig.ExtraLogDestinations[0]
Assert(t).AreEqual(logging.OUT_SOCKET, destination.Type, "should have been the socket type")
Assert(t).AreEqual("/var/log/p2-socket.out", destination.Path, "should have parsed path correctly")
}
开发者ID:robertabbott,项目名称:p2,代码行数:14,代码来源:setup_test.go
示例18: testPreparer
func testPreparer(t *testing.T, f *FakeStore) (*Preparer, *fakeHooks, string) {
podRoot, _ := ioutil.TempDir("", "pod_root")
cfg := &PreparerConfig{
NodeName: "hostname",
ConsulAddress: "0.0.0.0",
HooksDirectory: util.From(runtime.Caller(0)).ExpandPath("test_hooks"),
PodRoot: podRoot,
Auth: map[string]interface{}{"type": "none"},
}
p, err := New(cfg, logging.DefaultLogger)
Assert(t).IsNil(err, "Test setup error: should not have erred when trying to load a fake preparer")
hooks := &fakeHooks{}
p.hooks = hooks
p.store = f
return p, hooks, podRoot
}
开发者ID:tomzhang,项目名称:p2,代码行数:16,代码来源:orchestrate_test.go
示例19: TestInstallHooks
func TestInstallHooks(t *testing.T) {
destDir, _ := ioutil.TempDir("", "pods")
defer os.RemoveAll(destDir)
execDir, err := ioutil.TempDir("", "exec")
defer os.RemoveAll(execDir)
Assert(t).IsNil(err, "should not have erred creating a tempdir")
current, err := user.Current()
Assert(t).IsNil(err, "test setup: could not get the current user")
builder := manifest.NewBuilder()
builder.SetID("users")
builder.SetRunAsUser(current.Username)
builder.SetLaunchables(map[launch.LaunchableID]launch.LaunchableStanza{
"create": {
Location: util.From(runtime.Caller(0)).ExpandPath("testdata/hoisted-hello_def456.tar.gz"),
LaunchableType: "hoist",
},
})
podManifest := builder.GetManifest()
hookFactory := pods.NewHookFactory(destDir, "testNode")
hooksPod := hookFactory.NewHookPod(podManifest.ID())
preparer := Preparer{
hooksManifest: podManifest,
hooksPod: hooksPod,
hooksExecDir: execDir,
Logger: logging.DefaultLogger,
artifactRegistry: artifact.NewRegistry(nil, uri.DefaultFetcher, osversion.DefaultDetector),
artifactVerifier: auth.NopVerifier(),
}
err = preparer.InstallHooks()
Assert(t).IsNil(err, "There should not have been an error in the call to SyncOnce()")
currentAlias := filepath.Join(destDir, "users", "create", "current", "bin", "launch")
_, err = os.Stat(currentAlias)
Assert(t).IsNil(err, fmt.Sprintf("%s should have been created", currentAlias))
hookFile := filepath.Join(execDir, "users__create__launch")
_, err = os.Stat(hookFile)
Assert(t).IsNil(err, "should have created the user launch script")
}
开发者ID:petertseng,项目名称:p2,代码行数:43,代码来源:setup_test.go
示例20: FakeServiceBuilder
func FakeServiceBuilder() *ServiceBuilder {
testDir := os.TempDir()
fakeSBBinPath := util.From(runtime.Caller(0)).ExpandPath("fake_servicebuilder")
configRoot := filepath.Join(testDir, "/etc/servicebuilder.d")
os.MkdirAll(configRoot, 0755)
_, err := os.Stat(configRoot)
if err != nil {
panic("unable to create test dir")
}
stagingRoot := filepath.Join(testDir, "/var/service-stage")
os.MkdirAll(stagingRoot, 0755)
runitRoot := filepath.Join(testDir, "/var/service")
os.MkdirAll(runitRoot, 0755)
return &ServiceBuilder{
ConfigRoot: configRoot,
StagingRoot: stagingRoot,
RunitRoot: runitRoot,
Bin: fakeSBBinPath,
}
}
开发者ID:robertabbott,项目名称:p2,代码行数:21,代码来源:test_helper.go
注:本文中的github.com/square/p2/pkg/util.From函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论