/vendor/github.com/coreos/rkt/tests/rkt_cat_manifest_test.go

https://gitlab.com/unofficial-mirrors/openshift-origin · Go · 95 lines · 67 code · 12 blank · 16 comment · 11 complexity · 224bb86c910176cf01b747962cb0943d 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. // TestCatManifest tests 'rkt cat-manifest', it will:
  24. func TestCatManifest(t *testing.T) {
  25. const imgName = "rkt-cat-manifest-test"
  26. image := patchTestACI(fmt.Sprintf("%s.aci", imgName), fmt.Sprintf("--name=%s", imgName))
  27. defer os.Remove(image)
  28. imageHash := getHashOrPanic(image)
  29. imgID := ImageID{path: image, hash: imageHash}
  30. ctx := testutils.NewRktRunCtx()
  31. defer ctx.Cleanup()
  32. // Prepare image
  33. cmd := fmt.Sprintf("%s --insecure-options=image prepare %s", ctx.Cmd(), imgID.path)
  34. podUuid := runRktAndGetUUID(t, cmd)
  35. tmpDir := mustTempDir(imgName)
  36. defer os.RemoveAll(tmpDir)
  37. tests := []struct {
  38. uuid string
  39. match string
  40. uuidFile bool
  41. }{
  42. {
  43. podUuid,
  44. imgName,
  45. false,
  46. },
  47. {
  48. podUuid,
  49. imageHash[:20],
  50. false,
  51. },
  52. {
  53. "1234567890abcdef",
  54. "no matches found for",
  55. false,
  56. },
  57. {
  58. "",
  59. imageHash[:20],
  60. true,
  61. },
  62. }
  63. for i, tt := range tests {
  64. if tt.uuidFile == true {
  65. podUUID := runRktAndGetUUID(t, cmd)
  66. uuidFile, err := ioutil.TempFile(tmpDir, "uuid-file")
  67. if err != nil {
  68. panic(fmt.Sprintf("Cannot create uuid-file: %v", err))
  69. }
  70. uuidFilePath := uuidFile.Name()
  71. if err := ioutil.WriteFile(uuidFilePath, []byte(podUUID), 0600); err != nil {
  72. panic(fmt.Sprintf("Cannot write pod UUID to uuid-file: %v", err))
  73. }
  74. runCmd := fmt.Sprintf("%s cat-manifest --uuid-file=%s --pretty-print=false %s", ctx.Cmd(), uuidFilePath)
  75. t.Logf("Running test #%d", i)
  76. runRktAndCheckRegexOutput(t, runCmd, tt.match)
  77. } else {
  78. runCmd := fmt.Sprintf("%s cat-manifest --pretty-print=false %s", ctx.Cmd(), tt.uuid)
  79. t.Logf("Running test #%d", i)
  80. runRktAndCheckRegexOutput(t, runCmd, tt.match)
  81. }
  82. }
  83. }