provider_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package worker
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "path/filepath"
  7. "strconv"
  8. "testing"
  9. "time"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestRsyncProvider(t *testing.T) {
  13. Convey("Rsync Provider should work", t, func() {
  14. tmpDir, err := ioutil.TempDir("", "tunasync")
  15. defer os.RemoveAll(tmpDir)
  16. So(err, ShouldBeNil)
  17. scriptFile := filepath.Join(tmpDir, "myrsync")
  18. tmpFile := filepath.Join(tmpDir, "log_file")
  19. c := rsyncConfig{
  20. name: "tuna",
  21. upstreamURL: "rsync://rsync.tuna.moe/tuna/",
  22. rsyncCmd: scriptFile,
  23. workingDir: tmpDir,
  24. logDir: tmpDir,
  25. logFile: tmpFile,
  26. useIPv6: true,
  27. timeout: 100 * time.Second,
  28. interval: 600 * time.Second,
  29. }
  30. provider, err := newRsyncProvider(c)
  31. So(err, ShouldBeNil)
  32. So(provider.Type(), ShouldEqual, provRsync)
  33. So(provider.Name(), ShouldEqual, c.name)
  34. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  35. So(provider.LogDir(), ShouldEqual, c.logDir)
  36. So(provider.LogFile(), ShouldEqual, c.logFile)
  37. So(provider.Interval(), ShouldEqual, c.interval)
  38. So(provider.Timeout(), ShouldEqual, c.timeout)
  39. Convey("When entering a context (auto exit)", func() {
  40. func() {
  41. ctx := provider.EnterContext()
  42. defer provider.ExitContext()
  43. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  44. newWorkingDir := "/srv/mirror/working/tuna"
  45. ctx.Set(_WorkingDirKey, newWorkingDir)
  46. So(provider.WorkingDir(), ShouldEqual, newWorkingDir)
  47. }()
  48. Convey("After context is done", func() {
  49. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  50. })
  51. })
  52. Convey("When entering a context (manually exit)", func() {
  53. ctx := provider.EnterContext()
  54. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  55. newWorkingDir := "/srv/mirror/working/tuna"
  56. ctx.Set(_WorkingDirKey, newWorkingDir)
  57. So(provider.WorkingDir(), ShouldEqual, newWorkingDir)
  58. Convey("After context is done", func() {
  59. provider.ExitContext()
  60. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  61. })
  62. })
  63. Convey("Let's try a run", func() {
  64. scriptContent := `#!/bin/bash
  65. echo "syncing to $(pwd)"
  66. echo $RSYNC_PASSWORD $@
  67. sleep 1
  68. echo "Total file size: 1.33T bytes"
  69. echo "Done"
  70. exit 0
  71. `
  72. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  73. So(err, ShouldBeNil)
  74. targetDir, _ := filepath.EvalSymlinks(provider.WorkingDir())
  75. expectedOutput := fmt.Sprintf(
  76. "syncing to %s\n"+
  77. "%s\n"+
  78. "Total file size: 1.33T bytes\n"+
  79. "Done\n",
  80. targetDir,
  81. fmt.Sprintf(
  82. "-aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
  83. "--delete --delete-after --delay-updates --safe-links "+
  84. "--timeout=120 -6 %s %s",
  85. provider.upstreamURL, provider.WorkingDir(),
  86. ),
  87. )
  88. err = provider.Run(make(chan empty, 1))
  89. So(err, ShouldBeNil)
  90. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  91. So(err, ShouldBeNil)
  92. So(string(loggedContent), ShouldEqual, expectedOutput)
  93. // fmt.Println(string(loggedContent))
  94. So(provider.DataSize(), ShouldEqual, "1.33T")
  95. })
  96. })
  97. Convey("If the rsync program fails", t, func() {
  98. tmpDir, err := ioutil.TempDir("", "tunasync")
  99. defer os.RemoveAll(tmpDir)
  100. So(err, ShouldBeNil)
  101. tmpFile := filepath.Join(tmpDir, "log_file")
  102. Convey("in the rsyncProvider", func() {
  103. c := rsyncConfig{
  104. name: "tuna",
  105. upstreamURL: "rsync://rsync.tuna.moe/tuna/",
  106. workingDir: tmpDir,
  107. logDir: tmpDir,
  108. logFile: tmpFile,
  109. extraOptions: []string{"--somethine-invalid"},
  110. interval: 600 * time.Second,
  111. }
  112. provider, err := newRsyncProvider(c)
  113. So(err, ShouldBeNil)
  114. err = provider.Run(make(chan empty, 1))
  115. So(err, ShouldNotBeNil)
  116. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  117. So(err, ShouldBeNil)
  118. So(string(loggedContent), ShouldContainSubstring, "Syntax or usage error")
  119. })
  120. })
  121. }
  122. func TestRsyncProviderWithAuthentication(t *testing.T) {
  123. Convey("Rsync Provider with password should work", t, func() {
  124. tmpDir, err := ioutil.TempDir("", "tunasync")
  125. defer os.RemoveAll(tmpDir)
  126. So(err, ShouldBeNil)
  127. scriptFile := filepath.Join(tmpDir, "myrsync")
  128. tmpFile := filepath.Join(tmpDir, "log_file")
  129. proxyAddr := "127.0.0.1:1233"
  130. c := rsyncConfig{
  131. name: "tuna",
  132. upstreamURL: "rsync://rsync.tuna.moe/tuna/",
  133. rsyncCmd: scriptFile,
  134. username: "tunasync",
  135. password: "tunasyncpassword",
  136. workingDir: tmpDir,
  137. extraOptions: []string{"--delete-excluded"},
  138. rsyncEnv: map[string]string{"RSYNC_PROXY": proxyAddr},
  139. logDir: tmpDir,
  140. logFile: tmpFile,
  141. useIPv4: true,
  142. interval: 600 * time.Second,
  143. }
  144. provider, err := newRsyncProvider(c)
  145. So(err, ShouldBeNil)
  146. So(provider.Name(), ShouldEqual, c.name)
  147. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  148. So(provider.LogDir(), ShouldEqual, c.logDir)
  149. So(provider.LogFile(), ShouldEqual, c.logFile)
  150. So(provider.Interval(), ShouldEqual, c.interval)
  151. Convey("Let's try a run", func() {
  152. scriptContent := `#!/bin/bash
  153. echo "syncing to $(pwd)"
  154. echo $USER $RSYNC_PASSWORD $RSYNC_PROXY $@
  155. sleep 1
  156. echo "Done"
  157. exit 0
  158. `
  159. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  160. So(err, ShouldBeNil)
  161. targetDir, _ := filepath.EvalSymlinks(provider.WorkingDir())
  162. expectedOutput := fmt.Sprintf(
  163. "syncing to %s\n"+
  164. "%s\n"+
  165. "Done\n",
  166. targetDir,
  167. fmt.Sprintf(
  168. "%s %s %s -aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
  169. "--delete --delete-after --delay-updates --safe-links "+
  170. "--timeout=120 -4 --delete-excluded %s %s",
  171. provider.username, provider.password, proxyAddr,
  172. provider.upstreamURL, provider.WorkingDir(),
  173. ),
  174. )
  175. err = provider.Run(make(chan empty, 1))
  176. So(err, ShouldBeNil)
  177. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  178. So(err, ShouldBeNil)
  179. So(string(loggedContent), ShouldEqual, expectedOutput)
  180. // fmt.Println(string(loggedContent))
  181. })
  182. })
  183. }
  184. func TestRsyncProviderWithOverriddenOptions(t *testing.T) {
  185. Convey("Rsync Provider with overridden options should work", t, func() {
  186. tmpDir, err := ioutil.TempDir("", "tunasync")
  187. defer os.RemoveAll(tmpDir)
  188. So(err, ShouldBeNil)
  189. scriptFile := filepath.Join(tmpDir, "myrsync")
  190. tmpFile := filepath.Join(tmpDir, "log_file")
  191. c := rsyncConfig{
  192. name: "tuna",
  193. upstreamURL: "rsync://rsync.tuna.moe/tuna/",
  194. rsyncCmd: scriptFile,
  195. workingDir: tmpDir,
  196. overriddenOptions: []string{"-aHvh", "--no-o", "--no-g", "--stats"},
  197. extraOptions: []string{"--delete-excluded"},
  198. logDir: tmpDir,
  199. logFile: tmpFile,
  200. useIPv6: true,
  201. interval: 600 * time.Second,
  202. }
  203. provider, err := newRsyncProvider(c)
  204. So(err, ShouldBeNil)
  205. So(provider.Name(), ShouldEqual, c.name)
  206. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  207. So(provider.LogDir(), ShouldEqual, c.logDir)
  208. So(provider.LogFile(), ShouldEqual, c.logFile)
  209. So(provider.Interval(), ShouldEqual, c.interval)
  210. Convey("Let's try a run", func() {
  211. scriptContent := `#!/bin/bash
  212. echo "syncing to $(pwd)"
  213. echo $@
  214. sleep 1
  215. echo "Done"
  216. exit 0
  217. `
  218. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  219. So(err, ShouldBeNil)
  220. targetDir, _ := filepath.EvalSymlinks(provider.WorkingDir())
  221. expectedOutput := fmt.Sprintf(
  222. "syncing to %s\n"+
  223. "-aHvh --no-o --no-g --stats -6 --delete-excluded %s %s\n"+
  224. "Done\n",
  225. targetDir,
  226. provider.upstreamURL,
  227. provider.WorkingDir(),
  228. )
  229. err = provider.Run(make(chan empty, 1))
  230. So(err, ShouldBeNil)
  231. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  232. So(err, ShouldBeNil)
  233. So(string(loggedContent), ShouldEqual, expectedOutput)
  234. // fmt.Println(string(loggedContent))
  235. })
  236. })
  237. }
  238. func TestCmdProvider(t *testing.T) {
  239. Convey("Command Provider should work", t, func(ctx C) {
  240. tmpDir, err := ioutil.TempDir("", "tunasync")
  241. defer os.RemoveAll(tmpDir)
  242. So(err, ShouldBeNil)
  243. scriptFile := filepath.Join(tmpDir, "cmd.sh")
  244. tmpFile := filepath.Join(tmpDir, "log_file")
  245. c := cmdConfig{
  246. name: "tuna-cmd",
  247. upstreamURL: "http://mirrors.tuna.moe/",
  248. command: "bash " + scriptFile,
  249. workingDir: tmpDir,
  250. logDir: tmpDir,
  251. logFile: tmpFile,
  252. interval: 600 * time.Second,
  253. env: map[string]string{
  254. "AOSP_REPO_BIN": "/usr/local/bin/repo",
  255. },
  256. }
  257. provider, err := newCmdProvider(c)
  258. So(err, ShouldBeNil)
  259. So(provider.Type(), ShouldEqual, provCommand)
  260. So(provider.Name(), ShouldEqual, c.name)
  261. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  262. So(provider.LogDir(), ShouldEqual, c.logDir)
  263. So(provider.LogFile(), ShouldEqual, c.logFile)
  264. So(provider.Interval(), ShouldEqual, c.interval)
  265. Convey("Let's try to run a simple command", func() {
  266. scriptContent := `#!/bin/bash
  267. echo $TUNASYNC_WORKING_DIR
  268. echo $TUNASYNC_MIRROR_NAME
  269. echo $TUNASYNC_UPSTREAM_URL
  270. echo $TUNASYNC_LOG_FILE
  271. echo $AOSP_REPO_BIN
  272. `
  273. expectedOutput := fmt.Sprintf(
  274. "%s\n%s\n%s\n%s\n%s\n",
  275. provider.WorkingDir(),
  276. provider.Name(),
  277. provider.upstreamURL,
  278. provider.LogFile(),
  279. "/usr/local/bin/repo",
  280. )
  281. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  282. So(err, ShouldBeNil)
  283. readedScriptContent, err := ioutil.ReadFile(scriptFile)
  284. So(err, ShouldBeNil)
  285. So(readedScriptContent, ShouldResemble, []byte(scriptContent))
  286. err = provider.Run(make(chan empty, 1))
  287. So(err, ShouldBeNil)
  288. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  289. So(err, ShouldBeNil)
  290. So(string(loggedContent), ShouldEqual, expectedOutput)
  291. })
  292. Convey("If a command fails", func() {
  293. scriptContent := `exit 1`
  294. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  295. So(err, ShouldBeNil)
  296. readedScriptContent, err := ioutil.ReadFile(scriptFile)
  297. So(err, ShouldBeNil)
  298. So(readedScriptContent, ShouldResemble, []byte(scriptContent))
  299. err = provider.Run(make(chan empty, 1))
  300. So(err, ShouldNotBeNil)
  301. })
  302. Convey("If a long job is killed", func(ctx C) {
  303. scriptContent := `#!/bin/bash
  304. sleep 10
  305. `
  306. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  307. So(err, ShouldBeNil)
  308. started := make(chan empty, 1)
  309. go func() {
  310. err := provider.Run(started)
  311. ctx.So(err, ShouldNotBeNil)
  312. }()
  313. <-started
  314. So(provider.IsRunning(), ShouldBeTrue)
  315. time.Sleep(1 * time.Second)
  316. err = provider.Terminate()
  317. So(err, ShouldBeNil)
  318. })
  319. })
  320. Convey("Command Provider without log file should work", t, func(ctx C) {
  321. tmpDir, err := ioutil.TempDir("", "tunasync")
  322. defer os.RemoveAll(tmpDir)
  323. So(err, ShouldBeNil)
  324. c := cmdConfig{
  325. name: "run-ls",
  326. upstreamURL: "http://mirrors.tuna.moe/",
  327. command: "ls",
  328. workingDir: tmpDir,
  329. logDir: tmpDir,
  330. logFile: "/dev/null",
  331. interval: 600 * time.Second,
  332. }
  333. provider, err := newCmdProvider(c)
  334. So(err, ShouldBeNil)
  335. So(provider.IsMaster(), ShouldEqual, false)
  336. So(provider.ZFS(), ShouldBeNil)
  337. So(provider.Type(), ShouldEqual, provCommand)
  338. So(provider.Name(), ShouldEqual, c.name)
  339. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  340. So(provider.LogDir(), ShouldEqual, c.logDir)
  341. So(provider.LogFile(), ShouldEqual, c.logFile)
  342. So(provider.Interval(), ShouldEqual, c.interval)
  343. Convey("Run the command", func() {
  344. err = provider.Run(make(chan empty, 1))
  345. So(err, ShouldBeNil)
  346. })
  347. })
  348. Convey("Command Provider with RegExprs should work", t, func(ctx C) {
  349. tmpDir, err := ioutil.TempDir("", "tunasync")
  350. defer os.RemoveAll(tmpDir)
  351. So(err, ShouldBeNil)
  352. tmpFile := filepath.Join(tmpDir, "log_file")
  353. c := cmdConfig{
  354. name: "run-uptime",
  355. upstreamURL: "http://mirrors.tuna.moe/",
  356. command: "uptime",
  357. failOnMatch: "",
  358. sizePattern: "",
  359. workingDir: tmpDir,
  360. logDir: tmpDir,
  361. logFile: tmpFile,
  362. interval: 600 * time.Second,
  363. }
  364. Convey("when fail-on-match regexp matches", func() {
  365. c.failOnMatch = `[a-z]+`
  366. provider, err := newCmdProvider(c)
  367. So(err, ShouldBeNil)
  368. err = provider.Run(make(chan empty, 1))
  369. So(err, ShouldNotBeNil)
  370. So(provider.DataSize(), ShouldBeEmpty)
  371. })
  372. Convey("when fail-on-match regexp does not match", func() {
  373. c.failOnMatch = `load average_`
  374. provider, err := newCmdProvider(c)
  375. So(err, ShouldBeNil)
  376. err = provider.Run(make(chan empty, 1))
  377. So(err, ShouldBeNil)
  378. })
  379. Convey("when fail-on-match regexp meets /dev/null", func() {
  380. c.failOnMatch = `load average_`
  381. c.logFile = "/dev/null"
  382. provider, err := newCmdProvider(c)
  383. So(err, ShouldBeNil)
  384. err = provider.Run(make(chan empty, 1))
  385. So(err, ShouldNotBeNil)
  386. })
  387. Convey("when size-pattern regexp matches", func() {
  388. c.sizePattern = `load average: ([\d\.]+)`
  389. provider, err := newCmdProvider(c)
  390. So(err, ShouldBeNil)
  391. err = provider.Run(make(chan empty, 1))
  392. So(err, ShouldBeNil)
  393. So(provider.DataSize(), ShouldNotBeEmpty)
  394. _, err = strconv.ParseFloat(provider.DataSize(), 32)
  395. So(err, ShouldBeNil)
  396. })
  397. Convey("when size-pattern regexp does not match", func() {
  398. c.sizePattern = `load ave: ([\d\.]+)`
  399. provider, err := newCmdProvider(c)
  400. So(err, ShouldBeNil)
  401. err = provider.Run(make(chan empty, 1))
  402. So(err, ShouldBeNil)
  403. So(provider.DataSize(), ShouldBeEmpty)
  404. })
  405. Convey("when size-pattern regexp meets /dev/null", func() {
  406. c.sizePattern = `load ave: ([\d\.]+)`
  407. c.logFile = "/dev/null"
  408. provider, err := newCmdProvider(c)
  409. So(err, ShouldBeNil)
  410. err = provider.Run(make(chan empty, 1))
  411. So(err, ShouldNotBeNil)
  412. So(provider.DataSize(), ShouldBeEmpty)
  413. })
  414. })
  415. }
  416. func TestTwoStageRsyncProvider(t *testing.T) {
  417. Convey("TwoStageRsync Provider should work", t, func(ctx C) {
  418. tmpDir, err := ioutil.TempDir("", "tunasync")
  419. defer os.RemoveAll(tmpDir)
  420. So(err, ShouldBeNil)
  421. scriptFile := filepath.Join(tmpDir, "myrsync")
  422. tmpFile := filepath.Join(tmpDir, "log_file")
  423. c := twoStageRsyncConfig{
  424. name: "tuna-two-stage-rsync",
  425. upstreamURL: "rsync://mirrors.tuna.moe/",
  426. stage1Profile: "debian",
  427. rsyncCmd: scriptFile,
  428. workingDir: tmpDir,
  429. logDir: tmpDir,
  430. logFile: tmpFile,
  431. useIPv6: true,
  432. excludeFile: tmpFile,
  433. extraOptions: []string{"--delete-excluded", "--cache"},
  434. username: "hello",
  435. password: "world",
  436. }
  437. provider, err := newTwoStageRsyncProvider(c)
  438. So(err, ShouldBeNil)
  439. So(provider.Type(), ShouldEqual, provTwoStageRsync)
  440. So(provider.Name(), ShouldEqual, c.name)
  441. So(provider.WorkingDir(), ShouldEqual, c.workingDir)
  442. So(provider.LogDir(), ShouldEqual, c.logDir)
  443. So(provider.LogFile(), ShouldEqual, c.logFile)
  444. So(provider.Interval(), ShouldEqual, c.interval)
  445. Convey("Try a command", func(ctx C) {
  446. scriptContent := `#!/bin/bash
  447. echo "syncing to $(pwd)"
  448. echo $@
  449. sleep 1
  450. echo "Done"
  451. exit 0
  452. `
  453. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  454. So(err, ShouldBeNil)
  455. err = provider.Run(make(chan empty, 2))
  456. So(err, ShouldBeNil)
  457. targetDir, _ := filepath.EvalSymlinks(provider.WorkingDir())
  458. expectedOutput := fmt.Sprintf(
  459. "syncing to %s\n"+
  460. "%s\n"+
  461. "Done\n"+
  462. "syncing to %s\n"+
  463. "%s\n"+
  464. "Done\n",
  465. targetDir,
  466. fmt.Sprintf(
  467. "-aHvh --no-o --no-g --stats --exclude .~tmp~/ --safe-links "+
  468. "--timeout=120 --exclude dists/ -6 "+
  469. "--exclude-from %s %s %s",
  470. provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
  471. ),
  472. targetDir,
  473. fmt.Sprintf(
  474. "-aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
  475. "--delete --delete-after --delay-updates --safe-links "+
  476. "--timeout=120 --delete-excluded --cache -6 --exclude-from %s %s %s",
  477. provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
  478. ),
  479. )
  480. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  481. So(err, ShouldBeNil)
  482. So(string(loggedContent), ShouldEqual, expectedOutput)
  483. // fmt.Println(string(loggedContent))
  484. })
  485. Convey("Try terminating", func(ctx C) {
  486. scriptContent := `#!/bin/bash
  487. echo $@
  488. sleep 10
  489. exit 0
  490. `
  491. err = ioutil.WriteFile(scriptFile, []byte(scriptContent), 0755)
  492. So(err, ShouldBeNil)
  493. started := make(chan empty, 2)
  494. go func() {
  495. err := provider.Run(started)
  496. ctx.So(err, ShouldNotBeNil)
  497. }()
  498. <-started
  499. So(provider.IsRunning(), ShouldBeTrue)
  500. time.Sleep(1 * time.Second)
  501. err = provider.Terminate()
  502. So(err, ShouldBeNil)
  503. expectedOutput := fmt.Sprintf(
  504. "-aHvh --no-o --no-g --stats --exclude .~tmp~/ --safe-links "+
  505. "--timeout=120 --exclude dists/ -6 "+
  506. "--exclude-from %s %s %s\n",
  507. provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
  508. )
  509. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  510. So(err, ShouldBeNil)
  511. So(string(loggedContent), ShouldStartWith, expectedOutput)
  512. // fmt.Println(string(loggedContent))
  513. })
  514. })
  515. Convey("If the rsync program fails", t, func(ctx C) {
  516. tmpDir, err := ioutil.TempDir("", "tunasync")
  517. defer os.RemoveAll(tmpDir)
  518. So(err, ShouldBeNil)
  519. tmpFile := filepath.Join(tmpDir, "log_file")
  520. Convey("in the twoStageRsyncProvider", func() {
  521. c := twoStageRsyncConfig{
  522. name: "tuna-two-stage-rsync",
  523. upstreamURL: "rsync://0.0.0.1/",
  524. stage1Profile: "debian",
  525. workingDir: tmpDir,
  526. logDir: tmpDir,
  527. logFile: tmpFile,
  528. excludeFile: tmpFile,
  529. }
  530. provider, err := newTwoStageRsyncProvider(c)
  531. So(err, ShouldBeNil)
  532. err = provider.Run(make(chan empty, 2))
  533. So(err, ShouldNotBeNil)
  534. loggedContent, err := ioutil.ReadFile(provider.LogFile())
  535. So(err, ShouldBeNil)
  536. So(string(loggedContent), ShouldContainSubstring, "Error in socket I/O")
  537. })
  538. })
  539. }