Signed-off-by: Alexander Morozov <lk4d4@docker.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,60 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "io/ioutil" |
|
| 5 |
+ "os" |
|
| 6 |
+ "os/exec" |
|
| 7 |
+ "path/filepath" |
|
| 8 |
+ "testing" |
|
| 9 |
+) |
|
| 10 |
+ |
|
| 11 |
+const v2binary = "registry-v2" |
|
| 12 |
+ |
|
| 13 |
+type testRegistryV2 struct {
|
|
| 14 |
+ URL string |
|
| 15 |
+ cmd *exec.Cmd |
|
| 16 |
+ dir string |
|
| 17 |
+} |
|
| 18 |
+ |
|
| 19 |
+func newTestRegistryV2(t *testing.T) (*testRegistryV2, error) {
|
|
| 20 |
+ template := `version: 0.1 |
|
| 21 |
+loglevel: debug |
|
| 22 |
+storage: |
|
| 23 |
+ filesystem: |
|
| 24 |
+ rootdirectory: %s |
|
| 25 |
+http: |
|
| 26 |
+ addr: :%s` |
|
| 27 |
+ tmp, err := ioutil.TempDir("", "registry-test-")
|
|
| 28 |
+ if err != nil {
|
|
| 29 |
+ return nil, err |
|
| 30 |
+ } |
|
| 31 |
+ confPath := filepath.Join(tmp, "config.yaml") |
|
| 32 |
+ config, err := os.Create(confPath) |
|
| 33 |
+ if err != nil {
|
|
| 34 |
+ return nil, err |
|
| 35 |
+ } |
|
| 36 |
+ if _, err := fmt.Fprintf(config, template, tmp, "5000"); err != nil {
|
|
| 37 |
+ os.RemoveAll(tmp) |
|
| 38 |
+ return nil, err |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 41 |
+ cmd := exec.Command(v2binary, confPath) |
|
| 42 |
+ if err := cmd.Start(); err != nil {
|
|
| 43 |
+ os.RemoveAll(tmp) |
|
| 44 |
+ if os.IsNotExist(err) {
|
|
| 45 |
+ t.Skip() |
|
| 46 |
+ } |
|
| 47 |
+ return nil, err |
|
| 48 |
+ } |
|
| 49 |
+ return &testRegistryV2{
|
|
| 50 |
+ cmd: cmd, |
|
| 51 |
+ dir: tmp, |
|
| 52 |
+ URL: "localhost:5000", |
|
| 53 |
+ }, nil |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+func (r *testRegistryV2) Close() {
|
|
| 57 |
+ r.cmd.Process.Kill() |
|
| 58 |
+ os.RemoveAll(r.dir) |
|
| 59 |
+} |