buildfile_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. package docker
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "net"
  8. "net/http"
  9. "net/http/httptest"
  10. "strings"
  11. "testing"
  12. "github.com/dotcloud/docker/archive"
  13. "github.com/dotcloud/docker/engine"
  14. "github.com/dotcloud/docker/image"
  15. "github.com/dotcloud/docker/nat"
  16. "github.com/dotcloud/docker/server"
  17. "github.com/dotcloud/docker/utils"
  18. )
  19. // A testContextTemplate describes a build context and how to test it
  20. type testContextTemplate struct {
  21. // Contents of the Dockerfile
  22. dockerfile string
  23. // Additional files in the context, eg [][2]string{"./passwd", "gordon"}
  24. files [][2]string
  25. // Additional remote files to host on a local HTTP server.
  26. remoteFiles [][2]string
  27. }
  28. func (context testContextTemplate) Archive(dockerfile string, t *testing.T) archive.Archive {
  29. input := []string{"Dockerfile", dockerfile}
  30. for _, pair := range context.files {
  31. input = append(input, pair[0], pair[1])
  32. }
  33. a, err := archive.Generate(input...)
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. return a
  38. }
  39. // A table of all the contexts to build and test.
  40. // A new docker runtime will be created and torn down for each context.
  41. var testContexts = []testContextTemplate{
  42. {
  43. `
  44. from {IMAGE}
  45. run sh -c 'echo root:testpass > /tmp/passwd'
  46. run mkdir -p /var/run/sshd
  47. run [ "$(cat /tmp/passwd)" = "root:testpass" ]
  48. run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ]
  49. `,
  50. nil,
  51. nil,
  52. },
  53. // Exactly the same as above, except uses a line split with a \ to test
  54. // multiline support.
  55. {
  56. `
  57. from {IMAGE}
  58. run sh -c 'echo root:testpass \
  59. > /tmp/passwd'
  60. run mkdir -p /var/run/sshd
  61. run [ "$(cat /tmp/passwd)" = "root:testpass" ]
  62. run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ]
  63. `,
  64. nil,
  65. nil,
  66. },
  67. // Line containing literal "\n"
  68. {
  69. `
  70. from {IMAGE}
  71. run sh -c 'echo root:testpass > /tmp/passwd'
  72. run echo "foo \n bar"; echo "baz"
  73. run mkdir -p /var/run/sshd
  74. run [ "$(cat /tmp/passwd)" = "root:testpass" ]
  75. run [ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ]
  76. `,
  77. nil,
  78. nil,
  79. },
  80. {
  81. `
  82. from {IMAGE}
  83. add foo /usr/lib/bla/bar
  84. run [ "$(cat /usr/lib/bla/bar)" = 'hello' ]
  85. add http://{SERVERADDR}/baz /usr/lib/baz/quux
  86. run [ "$(cat /usr/lib/baz/quux)" = 'world!' ]
  87. `,
  88. [][2]string{{"foo", "hello"}},
  89. [][2]string{{"/baz", "world!"}},
  90. },
  91. {
  92. `
  93. from {IMAGE}
  94. add f /
  95. run [ "$(cat /f)" = "hello" ]
  96. add f /abc
  97. run [ "$(cat /abc)" = "hello" ]
  98. add f /x/y/z
  99. run [ "$(cat /x/y/z)" = "hello" ]
  100. add f /x/y/d/
  101. run [ "$(cat /x/y/d/f)" = "hello" ]
  102. add d /
  103. run [ "$(cat /ga)" = "bu" ]
  104. add d /somewhere
  105. run [ "$(cat /somewhere/ga)" = "bu" ]
  106. add d /anotherplace/
  107. run [ "$(cat /anotherplace/ga)" = "bu" ]
  108. add d /somewheeeere/over/the/rainbooow
  109. run [ "$(cat /somewheeeere/over/the/rainbooow/ga)" = "bu" ]
  110. `,
  111. [][2]string{
  112. {"f", "hello"},
  113. {"d/ga", "bu"},
  114. },
  115. nil,
  116. },
  117. {
  118. `
  119. from {IMAGE}
  120. add http://{SERVERADDR}/x /a/b/c
  121. run [ "$(cat /a/b/c)" = "hello" ]
  122. add http://{SERVERADDR}/x?foo=bar /
  123. run [ "$(cat /x)" = "hello" ]
  124. add http://{SERVERADDR}/x /d/
  125. run [ "$(cat /d/x)" = "hello" ]
  126. add http://{SERVERADDR} /e
  127. run [ "$(cat /e)" = "blah" ]
  128. `,
  129. nil,
  130. [][2]string{{"/x", "hello"}, {"/", "blah"}},
  131. },
  132. // Comments, shebangs, and executability, oh my!
  133. {
  134. `
  135. FROM {IMAGE}
  136. # This is an ordinary comment.
  137. RUN { echo '#!/bin/sh'; echo 'echo hello world'; } > /hello.sh
  138. RUN [ ! -x /hello.sh ]
  139. RUN chmod +x /hello.sh
  140. RUN [ -x /hello.sh ]
  141. RUN [ "$(cat /hello.sh)" = $'#!/bin/sh\necho hello world' ]
  142. RUN [ "$(/hello.sh)" = "hello world" ]
  143. `,
  144. nil,
  145. nil,
  146. },
  147. // Users and groups
  148. {
  149. `
  150. FROM {IMAGE}
  151. # Make sure our defaults work
  152. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)" = '0:0/root:root' ]
  153. # TODO decide if "args.user = strconv.Itoa(syscall.Getuid())" is acceptable behavior for changeUser in sysvinit instead of "return nil" when "USER" isn't specified (so that we get the proper group list even if that is the empty list, even in the default case of not supplying an explicit USER to run as, which implies USER 0)
  154. USER root
  155. RUN [ "$(id -G):$(id -Gn)" = '0:root' ]
  156. # Setup dockerio user and group
  157. RUN echo 'dockerio:x:1000:1000::/bin:/bin/false' >> /etc/passwd
  158. RUN echo 'dockerio:x:1000:' >> /etc/group
  159. # Make sure we can switch to our user and all the information is exactly as we expect it to be
  160. USER dockerio
  161. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000:dockerio' ]
  162. # Switch back to root and double check that worked exactly as we might expect it to
  163. USER root
  164. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '0:0/root:root/0:root' ]
  165. # Add a "supplementary" group for our dockerio user
  166. RUN echo 'supplementary:x:1001:dockerio' >> /etc/group
  167. # ... and then go verify that we get it like we expect
  168. USER dockerio
  169. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000 1001:dockerio supplementary' ]
  170. USER 1000
  171. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000 1001:dockerio supplementary' ]
  172. # super test the new "user:group" syntax
  173. USER dockerio:dockerio
  174. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000:dockerio' ]
  175. USER 1000:dockerio
  176. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000:dockerio' ]
  177. USER dockerio:1000
  178. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000:dockerio' ]
  179. USER 1000:1000
  180. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1000/dockerio:dockerio/1000:dockerio' ]
  181. USER dockerio:supplementary
  182. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1001/dockerio:supplementary/1001:supplementary' ]
  183. USER dockerio:1001
  184. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1001/dockerio:supplementary/1001:supplementary' ]
  185. USER 1000:supplementary
  186. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1001/dockerio:supplementary/1001:supplementary' ]
  187. USER 1000:1001
  188. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1000:1001/dockerio:supplementary/1001:supplementary' ]
  189. # make sure unknown uid/gid still works properly
  190. USER 1042:1043
  191. RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1042:1043/1042:1043/1043:1043' ]
  192. `,
  193. nil,
  194. nil,
  195. },
  196. // Environment variable
  197. {
  198. `
  199. from {IMAGE}
  200. env FOO BAR
  201. run [ "$FOO" = "BAR" ]
  202. `,
  203. nil,
  204. nil,
  205. },
  206. // Environment overwriting
  207. {
  208. `
  209. from {IMAGE}
  210. env FOO BAR
  211. run [ "$FOO" = "BAR" ]
  212. env FOO BAZ
  213. run [ "$FOO" = "BAZ" ]
  214. `,
  215. nil,
  216. nil,
  217. },
  218. {
  219. `
  220. from {IMAGE}
  221. ENTRYPOINT /bin/echo
  222. CMD Hello world
  223. `,
  224. nil,
  225. nil,
  226. },
  227. {
  228. `
  229. from {IMAGE}
  230. VOLUME /test
  231. CMD Hello world
  232. `,
  233. nil,
  234. nil,
  235. },
  236. {
  237. `
  238. from {IMAGE}
  239. env FOO /foo/baz
  240. env BAR /bar
  241. env BAZ $BAR
  242. env FOOPATH $PATH:$FOO
  243. run [ "$BAR" = "$BAZ" ]
  244. run [ "$FOOPATH" = "$PATH:/foo/baz" ]
  245. `,
  246. nil,
  247. nil,
  248. },
  249. {
  250. `
  251. from {IMAGE}
  252. env FOO /bar
  253. env TEST testdir
  254. env BAZ /foobar
  255. add testfile $BAZ/
  256. add $TEST $FOO
  257. run [ "$(cat /foobar/testfile)" = "test1" ]
  258. run [ "$(cat /bar/withfile)" = "test2" ]
  259. `,
  260. [][2]string{
  261. {"testfile", "test1"},
  262. {"testdir/withfile", "test2"},
  263. },
  264. nil,
  265. },
  266. // JSON!
  267. {
  268. `
  269. FROM {IMAGE}
  270. RUN ["/bin/echo","hello","world"]
  271. CMD ["/bin/true"]
  272. ENTRYPOINT ["/bin/echo","your command -->"]
  273. `,
  274. nil,
  275. nil,
  276. },
  277. {
  278. `
  279. FROM {IMAGE}
  280. ADD test /test
  281. RUN ["chmod","+x","/test"]
  282. RUN ["/test"]
  283. RUN [ "$(cat /testfile)" = 'test!' ]
  284. `,
  285. [][2]string{
  286. {"test", "#!/bin/sh\necho 'test!' > /testfile"},
  287. },
  288. nil,
  289. },
  290. {
  291. `
  292. FROM {IMAGE}
  293. # what \
  294. RUN mkdir /testing
  295. RUN touch /testing/other
  296. `,
  297. nil,
  298. nil,
  299. },
  300. }
  301. // FIXME: test building with 2 successive overlapping ADD commands
  302. func constructDockerfile(template string, ip net.IP, port string) string {
  303. serverAddr := fmt.Sprintf("%s:%s", ip, port)
  304. replacer := strings.NewReplacer("{IMAGE}", unitTestImageID, "{SERVERADDR}", serverAddr)
  305. return replacer.Replace(template)
  306. }
  307. func mkTestingFileServer(files [][2]string) (*httptest.Server, error) {
  308. mux := http.NewServeMux()
  309. for _, file := range files {
  310. name, contents := file[0], file[1]
  311. mux.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) {
  312. w.Write([]byte(contents))
  313. })
  314. }
  315. // This is how httptest.NewServer sets up a net.Listener, except that our listener must accept remote
  316. // connections (from the container).
  317. listener, err := net.Listen("tcp", ":0")
  318. if err != nil {
  319. return nil, err
  320. }
  321. s := httptest.NewUnstartedServer(mux)
  322. s.Listener = listener
  323. s.Start()
  324. return s, nil
  325. }
  326. func TestBuild(t *testing.T) {
  327. for _, ctx := range testContexts {
  328. _, err := buildImage(ctx, t, nil, true)
  329. if err != nil {
  330. t.Fatal(err)
  331. }
  332. }
  333. }
  334. func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, useCache bool) (*image.Image, error) {
  335. if eng == nil {
  336. eng = NewTestEngine(t)
  337. runtime := mkDaemonFromEngine(eng, t)
  338. // FIXME: we might not need runtime, why not simply nuke
  339. // the engine?
  340. defer nuke(runtime)
  341. }
  342. srv := mkServerFromEngine(eng, t)
  343. httpServer, err := mkTestingFileServer(context.remoteFiles)
  344. if err != nil {
  345. t.Fatal(err)
  346. }
  347. defer httpServer.Close()
  348. idx := strings.LastIndex(httpServer.URL, ":")
  349. if idx < 0 {
  350. t.Fatalf("could not get port from test http server address %s", httpServer.URL)
  351. }
  352. port := httpServer.URL[idx+1:]
  353. iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
  354. if iIP == nil {
  355. t.Fatal("Legacy bridgeIP field not set in engine")
  356. }
  357. ip, ok := iIP.(net.IP)
  358. if !ok {
  359. panic("Legacy bridgeIP field in engine does not cast to net.IP")
  360. }
  361. dockerfile := constructDockerfile(context.dockerfile, ip, port)
  362. buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
  363. id, err := buildfile.Build(context.Archive(dockerfile, t))
  364. if err != nil {
  365. return nil, err
  366. }
  367. job := eng.Job("image_inspect", id)
  368. buffer := bytes.NewBuffer(nil)
  369. image := &image.Image{}
  370. job.Stdout.Add(buffer)
  371. if err := job.Run(); err != nil {
  372. return nil, err
  373. }
  374. err = json.NewDecoder(buffer).Decode(image)
  375. return image, err
  376. }
  377. // testing #1405 - config.Cmd does not get cleaned up if
  378. // utilizing cache
  379. func TestBuildEntrypointRunCleanup(t *testing.T) {
  380. eng := NewTestEngine(t)
  381. defer nuke(mkDaemonFromEngine(eng, t))
  382. img, err := buildImage(testContextTemplate{`
  383. from {IMAGE}
  384. run echo "hello"
  385. `,
  386. nil, nil}, t, eng, true)
  387. if err != nil {
  388. t.Fatal(err)
  389. }
  390. img, err = buildImage(testContextTemplate{`
  391. from {IMAGE}
  392. run echo "hello"
  393. add foo /foo
  394. entrypoint ["/bin/echo"]
  395. `,
  396. [][2]string{{"foo", "HEYO"}}, nil}, t, eng, true)
  397. if err != nil {
  398. t.Fatal(err)
  399. }
  400. if len(img.Config.Cmd) != 0 {
  401. t.Fail()
  402. }
  403. }
  404. func TestForbiddenContextPath(t *testing.T) {
  405. eng := NewTestEngine(t)
  406. defer nuke(mkDaemonFromEngine(eng, t))
  407. srv := mkServerFromEngine(eng, t)
  408. context := testContextTemplate{`
  409. from {IMAGE}
  410. maintainer dockerio
  411. add ../../ test/
  412. `,
  413. [][2]string{{"test.txt", "test1"}, {"other.txt", "other"}}, nil}
  414. httpServer, err := mkTestingFileServer(context.remoteFiles)
  415. if err != nil {
  416. t.Fatal(err)
  417. }
  418. defer httpServer.Close()
  419. idx := strings.LastIndex(httpServer.URL, ":")
  420. if idx < 0 {
  421. t.Fatalf("could not get port from test http server address %s", httpServer.URL)
  422. }
  423. port := httpServer.URL[idx+1:]
  424. iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
  425. if iIP == nil {
  426. t.Fatal("Legacy bridgeIP field not set in engine")
  427. }
  428. ip, ok := iIP.(net.IP)
  429. if !ok {
  430. panic("Legacy bridgeIP field in engine does not cast to net.IP")
  431. }
  432. dockerfile := constructDockerfile(context.dockerfile, ip, port)
  433. buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
  434. _, err = buildfile.Build(context.Archive(dockerfile, t))
  435. if err == nil {
  436. t.Log("Error should not be nil")
  437. t.Fail()
  438. }
  439. if err.Error() != "Forbidden path outside the build context: ../../ (/)" {
  440. t.Logf("Error message is not expected: %s", err.Error())
  441. t.Fail()
  442. }
  443. }
  444. func TestBuildADDFileNotFound(t *testing.T) {
  445. eng := NewTestEngine(t)
  446. defer nuke(mkDaemonFromEngine(eng, t))
  447. context := testContextTemplate{`
  448. from {IMAGE}
  449. add foo /usr/local/bar
  450. `,
  451. nil, nil}
  452. httpServer, err := mkTestingFileServer(context.remoteFiles)
  453. if err != nil {
  454. t.Fatal(err)
  455. }
  456. defer httpServer.Close()
  457. idx := strings.LastIndex(httpServer.URL, ":")
  458. if idx < 0 {
  459. t.Fatalf("could not get port from test http server address %s", httpServer.URL)
  460. }
  461. port := httpServer.URL[idx+1:]
  462. iIP := eng.Hack_GetGlobalVar("httpapi.bridgeIP")
  463. if iIP == nil {
  464. t.Fatal("Legacy bridgeIP field not set in engine")
  465. }
  466. ip, ok := iIP.(net.IP)
  467. if !ok {
  468. panic("Legacy bridgeIP field in engine does not cast to net.IP")
  469. }
  470. dockerfile := constructDockerfile(context.dockerfile, ip, port)
  471. buildfile := server.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
  472. _, err = buildfile.Build(context.Archive(dockerfile, t))
  473. if err == nil {
  474. t.Log("Error should not be nil")
  475. t.Fail()
  476. }
  477. if err.Error() != "foo: no such file or directory" {
  478. t.Logf("Error message is not expected: %s", err.Error())
  479. t.Fail()
  480. }
  481. }
  482. func TestBuildInheritance(t *testing.T) {
  483. eng := NewTestEngine(t)
  484. defer nuke(mkDaemonFromEngine(eng, t))
  485. img, err := buildImage(testContextTemplate{`
  486. from {IMAGE}
  487. expose 2375
  488. `,
  489. nil, nil}, t, eng, true)
  490. if err != nil {
  491. t.Fatal(err)
  492. }
  493. img2, _ := buildImage(testContextTemplate{fmt.Sprintf(`
  494. from %s
  495. entrypoint ["/bin/echo"]
  496. `, img.ID),
  497. nil, nil}, t, eng, true)
  498. if err != nil {
  499. t.Fatal(err)
  500. }
  501. // from child
  502. if img2.Config.Entrypoint[0] != "/bin/echo" {
  503. t.Fail()
  504. }
  505. // from parent
  506. if _, exists := img.Config.ExposedPorts[nat.NewPort("tcp", "2375")]; !exists {
  507. t.Fail()
  508. }
  509. }
  510. func TestBuildFails(t *testing.T) {
  511. _, err := buildImage(testContextTemplate{`
  512. from {IMAGE}
  513. run sh -c "exit 23"
  514. `,
  515. nil, nil}, t, nil, true)
  516. if err == nil {
  517. t.Fatal("Error should not be nil")
  518. }
  519. sterr, ok := err.(*utils.JSONError)
  520. if !ok {
  521. t.Fatalf("Error should be utils.JSONError")
  522. }
  523. if sterr.Code != 23 {
  524. t.Fatalf("StatusCode %d unexpected, should be 23", sterr.Code)
  525. }
  526. }
  527. func TestBuildFailsDockerfileEmpty(t *testing.T) {
  528. _, err := buildImage(testContextTemplate{``, nil, nil}, t, nil, true)
  529. if err != server.ErrDockerfileEmpty {
  530. t.Fatal("Expected: %v, got: %v", server.ErrDockerfileEmpty, err)
  531. }
  532. }
  533. func TestBuildOnBuildTrigger(t *testing.T) {
  534. _, err := buildImage(testContextTemplate{`
  535. from {IMAGE}
  536. onbuild run echo here is the trigger
  537. onbuild run touch foobar
  538. `,
  539. nil, nil,
  540. },
  541. t, nil, true,
  542. )
  543. if err != nil {
  544. t.Fatal(err)
  545. }
  546. // FIXME: test that the 'foobar' file was created in the final build.
  547. }
  548. func TestBuildOnBuildForbiddenChainedTrigger(t *testing.T) {
  549. _, err := buildImage(testContextTemplate{`
  550. from {IMAGE}
  551. onbuild onbuild run echo test
  552. `,
  553. nil, nil,
  554. },
  555. t, nil, true,
  556. )
  557. if err == nil {
  558. t.Fatal("Error should not be nil")
  559. }
  560. }
  561. func TestBuildOnBuildForbiddenFromTrigger(t *testing.T) {
  562. _, err := buildImage(testContextTemplate{`
  563. from {IMAGE}
  564. onbuild from {IMAGE}
  565. `,
  566. nil, nil,
  567. },
  568. t, nil, true,
  569. )
  570. if err == nil {
  571. t.Fatal("Error should not be nil")
  572. }
  573. }
  574. func TestBuildOnBuildForbiddenMaintainerTrigger(t *testing.T) {
  575. _, err := buildImage(testContextTemplate{`
  576. from {IMAGE}
  577. onbuild maintainer test
  578. `,
  579. nil, nil,
  580. },
  581. t, nil, true,
  582. )
  583. if err == nil {
  584. t.Fatal("Error should not be nil")
  585. }
  586. }
  587. // gh #2446
  588. func TestBuildAddToSymlinkDest(t *testing.T) {
  589. eng := NewTestEngine(t)
  590. defer nuke(mkDaemonFromEngine(eng, t))
  591. _, err := buildImage(testContextTemplate{`
  592. from {IMAGE}
  593. run mkdir /foo
  594. run ln -s /foo /bar
  595. add foo /bar/
  596. run stat /bar/foo
  597. `,
  598. [][2]string{{"foo", "HEYO"}}, nil}, t, eng, true)
  599. if err != nil {
  600. t.Fatal(err)
  601. }
  602. }