PageRenderTime 5286ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/rkt_exec_test.go

https://gitlab.com/github-cloud-corporation/rkt
Go | 98 lines | 64 code | 14 blank | 20 comment | 9 complexity | 91ec9d9f598979d8296c5d1810733ecb MD5 | raw file
  1. // Copyright 2015 The rkt Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build host coreos src kvm
  15. package main
  16. import (
  17. "fmt"
  18. "io/ioutil"
  19. "os"
  20. "testing"
  21. "github.com/coreos/rkt/tests/testutils"
  22. )
  23. const (
  24. noappManifestStr = `{"acKind":"ImageManifest","acVersion":"0.8.6","name":"coreos.com/rkt-inspect","labels":[{"name":"version","value":"1.13.0"},{"name":"arch","value":"amd64"},{"name":"os","value":"linux"}]}`
  25. )
  26. func TestRunOverrideExec(t *testing.T) {
  27. noappManifestFile := "noapp-manifest.json"
  28. if err := ioutil.WriteFile(noappManifestFile, []byte(noappManifestStr), 0600); err != nil {
  29. t.Fatalf("Cannot write noapp manifest: %v", err)
  30. }
  31. defer os.Remove(noappManifestFile)
  32. noappImage := patchTestACI("rkt-image-without-exec.aci", fmt.Sprintf("--manifest=%s", noappManifestFile))
  33. defer os.Remove(noappImage)
  34. execImage := patchTestACI("rkt-exec-override.aci", "--exec=/inspect")
  35. defer os.Remove(execImage)
  36. ctx := testutils.NewRktRunCtx()
  37. defer ctx.Cleanup()
  38. for _, tt := range []struct {
  39. rktCmd string
  40. expectedRegex string
  41. }{
  42. {
  43. // Sanity check - make sure no --exec override prints the expected exec invocation
  44. rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s -- --print-exec", ctx.Cmd(), execImage),
  45. expectedRegex: "inspect execed as: /inspect",
  46. },
  47. {
  48. // Now test overriding the entrypoint (which is a symlink to /inspect so should behave identically)
  49. rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s --exec /inspect-link -- --print-exec", ctx.Cmd(), execImage),
  50. expectedRegex: "inspect execed as: /inspect-link",
  51. },
  52. {
  53. // Test overriding the entrypoint with a relative path
  54. rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s --exec inspect-link-bin -- --print-exec", ctx.Cmd(), execImage),
  55. expectedRegex: "inspect execed as: .*inspect-link-bin",
  56. },
  57. {
  58. // Test overriding the entrypoint with a missing app section
  59. rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s --exec /inspect -- --print-exec", ctx.Cmd(), noappImage),
  60. expectedRegex: "inspect execed as: /inspect",
  61. },
  62. } {
  63. runRktAndCheckRegexOutput(t, tt.rktCmd, tt.expectedRegex)
  64. }
  65. }
  66. func TestRunPreparedOverrideExec(t *testing.T) {
  67. execImage := patchTestACI("rkt-exec-override.aci", "--exec=/inspect")
  68. defer os.Remove(execImage)
  69. ctx := testutils.NewRktRunCtx()
  70. defer ctx.Cleanup()
  71. var rktCmd, uuid, expected string
  72. // Sanity check - make sure no --exec override prints the expected exec invocation
  73. rktCmd = fmt.Sprintf("%s prepare --insecure-options=image %s -- --print-exec", ctx.Cmd(), execImage)
  74. uuid = runRktAndGetUUID(t, rktCmd)
  75. rktCmd = fmt.Sprintf("%s run-prepared --mds-register=false %s", ctx.Cmd(), uuid)
  76. expected = "inspect execed as: /inspect"
  77. runRktAndCheckOutput(t, rktCmd, expected, false)
  78. // Now test overriding the entrypoint (which is a symlink to /inspect so should behave identically)
  79. rktCmd = fmt.Sprintf("%s prepare --insecure-options=image %s --exec /inspect-link -- --print-exec", ctx.Cmd(), execImage)
  80. uuid = runRktAndGetUUID(t, rktCmd)
  81. rktCmd = fmt.Sprintf("%s run-prepared --mds-register=false %s", ctx.Cmd(), uuid)
  82. expected = "inspect execed as: /inspect-link"
  83. runRktAndCheckOutput(t, rktCmd, expected, false)
  84. }