provider_test.go 17 KB

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