MCPcopy
hub / github.com/tuna/tunasync / TestDocker

Function TestDocker

worker/docker_test.go:41–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func 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
64echo ${TEST_CONTENT}
65sleep 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 }()

Callers

nothing calls this directly

Calls 13

preExecMethod · 0.95
NameMethod · 0.95
postExecMethod · 0.95
newCmdProviderFunction · 0.85
cmdRunFunction · 0.85
getDockerByNameFunction · 0.85
DebugfMethod · 0.80
ErrorfMethod · 0.80
AddHookMethod · 0.65
DockerMethod · 0.65
RunMethod · 0.65
TerminateMethod · 0.65

Tested by

no test coverage detected