|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe Metatron::Templates::VolumeSnapshotContent do |
| 4 | + describe "for simple volume snapshot contents" do |
| 5 | + let(:volume_snapshot_content) do |
| 6 | + described_class.new( |
| 7 | + "new-snapshot-content-test", |
| 8 | + source: { snapshotHandle: "7bdd0de3-aaeb-11e8-9aae-0242ac110002" }, |
| 9 | + driver: "hostpath.csi.k8s.io", |
| 10 | + volume_snapshot_ref: { |
| 11 | + name: "new-snapshot-test", |
| 12 | + namespace: "foo" |
| 13 | + } |
| 14 | + ) |
| 15 | + end |
| 16 | + |
| 17 | + let(:rendered_volume_snapshot_content) do |
| 18 | + { |
| 19 | + apiVersion: "snapshot.storage.k8s.io/v1", |
| 20 | + kind: "VolumeSnapshotContent", |
| 21 | + metadata: { |
| 22 | + name: "new-snapshot-content-test", |
| 23 | + labels: { "metatron.therubyist.org/name": "new-snapshot-content-test" } |
| 24 | + }, |
| 25 | + spec: { |
| 26 | + deletionPolicy: "Delete", |
| 27 | + driver: "hostpath.csi.k8s.io", |
| 28 | + source: { |
| 29 | + snapshotHandle: "7bdd0de3-aaeb-11e8-9aae-0242ac110002" |
| 30 | + }, |
| 31 | + sourceVolumeMode: "Filesystem", |
| 32 | + volumeSnapshotRef: { |
| 33 | + name: "new-snapshot-test", |
| 34 | + namespace: "foo" |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + end |
| 39 | + |
| 40 | + it "produces a hash" do |
| 41 | + expect(volume_snapshot_content.render).to be_a(Hash) |
| 42 | + end |
| 43 | + |
| 44 | + it "renders properly" do |
| 45 | + expect(volume_snapshot_content.render).to eq(rendered_volume_snapshot_content) |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + describe "for volume snapshot contents provided a volume snapshot" do |
| 50 | + let(:volume_snapshot) do |
| 51 | + snapshot = Metatron::Templates::VolumeSnapshot.new( |
| 52 | + "new-snapshot-test", |
| 53 | + source: { persistentVolumeClaimName: "hello" }, |
| 54 | + volume_snapshot_class_name: "testClass" |
| 55 | + ) |
| 56 | + snapshot.namespace = "foo" |
| 57 | + snapshot |
| 58 | + end |
| 59 | + |
| 60 | + let(:volume_snapshot_content) do |
| 61 | + described_class.new( |
| 62 | + "new-snapshot-content-test", |
| 63 | + source: { snapshotHandle: "7bdd0de3-aaeb-11e8-9aae-0242ac110003" }, |
| 64 | + driver: "hostpath.csi.k8s.io", |
| 65 | + volume_snapshot_ref: volume_snapshot |
| 66 | + ) |
| 67 | + end |
| 68 | + |
| 69 | + let(:rendered_volume_snapshot_content) do |
| 70 | + { |
| 71 | + apiVersion: "snapshot.storage.k8s.io/v1", |
| 72 | + kind: "VolumeSnapshotContent", |
| 73 | + metadata: { |
| 74 | + name: "new-snapshot-content-test", |
| 75 | + labels: { "metatron.therubyist.org/name": "new-snapshot-content-test" } |
| 76 | + }, |
| 77 | + spec: { |
| 78 | + deletionPolicy: "Delete", |
| 79 | + driver: "hostpath.csi.k8s.io", |
| 80 | + source: { |
| 81 | + snapshotHandle: "7bdd0de3-aaeb-11e8-9aae-0242ac110003" |
| 82 | + }, |
| 83 | + sourceVolumeMode: "Filesystem", |
| 84 | + volumeSnapshotRef: { |
| 85 | + name: "new-snapshot-test", |
| 86 | + namespace: "foo" |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + end |
| 91 | + |
| 92 | + it "produces a hash" do |
| 93 | + expect(volume_snapshot_content.render).to be_a(Hash) |
| 94 | + end |
| 95 | + |
| 96 | + it "renders properly" do |
| 97 | + expect(volume_snapshot_content.render).to eq(rendered_volume_snapshot_content) |
| 98 | + end |
| 99 | + end |
| 100 | +end |
0 commit comments