(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func TestDocker(t *testing.T) { |
| 42 | Convey("Docker Should Work", t, func(ctx C) { |
| 43 | tmpDir, err := os.MkdirTemp("", "tunasync") |
| 44 | defer os.RemoveAll(tmpDir) |
| 45 | So(err, ShouldBeNil) |
| 46 | cmdScript := filepath.Join(tmpDir, "cmd.sh") |
| 47 | tmpFile := filepath.Join(tmpDir, "log_file") |
| 48 | expectedOutput := "HELLO_WORLD" |
| 49 | |
| 50 | c := cmdConfig{ |
| 51 | name: "tuna-docker", |
| 52 | upstreamURL: "http://mirrors.tuna.moe/", |
| 53 | command: "/bin/cmd.sh", |
| 54 | workingDir: tmpDir, |
| 55 | logDir: tmpDir, |
| 56 | logFile: tmpFile, |
| 57 | interval: 600 * time.Second, |
| 58 | env: map[string]string{ |
| 59 | "TEST_CONTENT": expectedOutput, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | cmdScriptContent := `#!/bin/sh |
| 64 | echo ${TEST_CONTENT} |
| 65 | sleep 20 |
| 66 | ` |
| 67 | err = os.WriteFile(cmdScript, []byte(cmdScriptContent), 0755) |
| 68 | So(err, ShouldBeNil) |
| 69 | |
| 70 | provider, err := newCmdProvider(c) |
| 71 | So(err, ShouldBeNil) |
| 72 | |
| 73 | d := &dockerHook{ |
| 74 | emptyHook: emptyHook{ |
| 75 | provider: provider, |
| 76 | }, |
| 77 | image: "alpine:3.23", |
| 78 | volumes: []string{ |
| 79 | fmt.Sprintf("%s:%s", cmdScript, "/bin/cmd.sh"), |
| 80 | }, |
| 81 | memoryLimit: 512 * units.MiB, |
| 82 | } |
| 83 | provider.AddHook(d) |
| 84 | So(provider.Docker(), ShouldNotBeNil) |
| 85 | |
| 86 | err = d.preExec() |
| 87 | So(err, ShouldBeNil) |
| 88 | |
| 89 | cmdRun("docker", []string{"images"}) |
| 90 | exitedErr := make(chan error, 1) |
| 91 | go func() { |
| 92 | err = provider.Run(make(chan empty, 1)) |
| 93 | logger.Debugf("provider.Run() exited") |
| 94 | if err != nil { |
| 95 | logger.Errorf("provider.Run() failed: %v", err) |
| 96 | } |
| 97 | exitedErr <- err |
| 98 | }() |
nothing calls this directly
no test coverage detected