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

Function TestRsyncProviderWithAuthentication

worker/provider_test.go:140–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestRsyncProviderWithAuthentication(t *testing.T) {
141 Convey("Rsync Provider with password should work", t, func() {
142 tmpDir, err := os.MkdirTemp("", "tunasync")
143 defer os.RemoveAll(tmpDir)
144 So(err, ShouldBeNil)
145 scriptFile := filepath.Join(tmpDir, "myrsync")
146 tmpFile := filepath.Join(tmpDir, "log_file")
147 proxyAddr := "127.0.0.1:1233"
148
149 c := rsyncConfig{
150 name: "tuna",
151 upstreamURL: "rsync://rsync.tuna.moe/tuna/",
152 rsyncCmd: scriptFile,
153 username: "tunasync",
154 password: "tunasyncpassword",
155 workingDir: tmpDir,
156 extraOptions: []string{"--delete-excluded"},
157 rsyncTimeoutValue: 30,
158 rsyncEnv: map[string]string{"RSYNC_PROXY": proxyAddr},
159 logDir: tmpDir,
160 logFile: tmpFile,
161 useIPv4: true,
162 interval: 600 * time.Second,
163 }
164
165 provider, err := newRsyncProvider(c)
166 So(err, ShouldBeNil)
167
168 So(provider.Name(), ShouldEqual, c.name)
169 So(provider.WorkingDir(), ShouldEqual, c.workingDir)
170 So(provider.LogDir(), ShouldEqual, c.logDir)
171 So(provider.LogFile(), ShouldEqual, c.logFile)
172 So(provider.Interval(), ShouldEqual, c.interval)
173
174 Convey("Let's try a run", func() {
175 scriptContent := `#!/bin/bash
176echo "syncing to $(pwd)"
177echo $USER $RSYNC_PASSWORD $RSYNC_PROXY $@
178sleep 1
179echo "Done"
180exit 0
181 `
182 err = os.WriteFile(scriptFile, []byte(scriptContent), 0755)
183 So(err, ShouldBeNil)
184
185 targetDir, _ := filepath.EvalSymlinks(provider.WorkingDir())
186 expectedOutput := fmt.Sprintf(
187 "syncing to %s\n"+
188 "%s\n"+
189 "Done\n",
190 targetDir,
191 fmt.Sprintf(
192 "%s %s %s -aHvh --no-o --no-g --stats --filter risk .~tmp~/ --exclude .~tmp~/ "+
193 "--delete --delete-after --delay-updates --safe-links "+
194 "--timeout=30 -4 --delete-excluded %s %s",
195 provider.username, provider.password, proxyAddr,
196 provider.upstreamURL, provider.WorkingDir(),
197 ),

Callers

nothing calls this directly

Calls 7

newRsyncProviderFunction · 0.85
NameMethod · 0.65
WorkingDirMethod · 0.65
LogDirMethod · 0.65
LogFileMethod · 0.65
IntervalMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected