From cf62cf0f1e9aae094ed97ec8a02399d65aa49f06 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 12 Jan 2015 13:26:49 -0800 Subject: [PATCH] RegistryV2 datastructure for tests Signed-off-by: Alexander Morozov Upstream-commit: 2fc2862a73dbbc612f59f61f66c465d2e48bcbea Component: engine --- components/engine/integration-cli/registry.go | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 components/engine/integration-cli/registry.go diff --git a/components/engine/integration-cli/registry.go b/components/engine/integration-cli/registry.go new file mode 100644 index 0000000000..f0ef05cca1 --- /dev/null +++ b/components/engine/integration-cli/registry.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "testing" +) + +const v2binary = "registry-v2" + +type testRegistryV2 struct { + URL string + cmd *exec.Cmd + dir string +} + +func newTestRegistryV2(t *testing.T) (*testRegistryV2, error) { + template := `version: 0.1 +loglevel: debug +storage: + filesystem: + rootdirectory: %s +http: + addr: :%s` + tmp, err := ioutil.TempDir("", "registry-test-") + if err != nil { + return nil, err + } + confPath := filepath.Join(tmp, "config.yaml") + config, err := os.Create(confPath) + if err != nil { + return nil, err + } + if _, err := fmt.Fprintf(config, template, tmp, "5000"); err != nil { + os.RemoveAll(tmp) + return nil, err + } + + cmd := exec.Command(v2binary, confPath) + if err := cmd.Start(); err != nil { + os.RemoveAll(tmp) + if os.IsNotExist(err) { + t.Skip() + } + return nil, err + } + return &testRegistryV2{ + cmd: cmd, + dir: tmp, + URL: "localhost:5000", + }, nil +} + +func (r *testRegistryV2) Close() { + r.cmd.Process.Kill() + os.RemoveAll(r.dir) +}