File: mappers_test.rb

package info (click to toggle)
vagrant 2.3.7%2Bgit20230731.5fc64cde%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,616 kB
  • sloc: ruby: 111,820; sh: 462; makefile: 123; ansic: 34; lisp: 1
file content (71 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require File.expand_path("../../../base", __dir__)

require Vagrant.source_root.join("plugins/commands/serve/command")

describe VagrantPlugins::CommandServe::Mappers do
  include_context "unit"

  subject { described_class.new }

  context "Hash" do
    it "unwraps wrapper types when they show up in the Hash" do
      input = Hashicorp::Vagrant::Sdk::Args::Hash.new(
        entries: [
          Hashicorp::Vagrant::Sdk::Args::HashEntry.new(
            key: Google::Protobuf::Any.pack(
              Hashicorp::Vagrant::Sdk::Args::Symbol.new(str: "error_check")
            ),
            value: Google::Protobuf::Any.pack(
              Google::Protobuf::BoolValue.new(value: false)
            )
          )
        ]
      )
      output = subject.map(input, to: Hash)

      expect(output[:error_check]).to eq(false)

      input = Hashicorp::Vagrant::Sdk::Args::Hash.new(
        entries: [
          Hashicorp::Vagrant::Sdk::Args::HashEntry.new(
            key: Google::Protobuf::Any.pack(
              Google::Protobuf::StringValue.new(value: "error_check")
            ),
            value: Google::Protobuf::Any.pack(
              Google::Protobuf::BoolValue.new(value: false)
            )
          )
        ]
      )
      output = subject.map(input, to: Hash)

      expect(output["error_check"]).to eq(false)
    end
  end

  context "Array" do
    it "unwraps wrapper types when they show up in the Array" do
      input = Hashicorp::Vagrant::Sdk::Args::Array.new(
        list: [
          Google::Protobuf::Any.pack(
            Google::Protobuf::BoolValue.new(value: false)
          ),
        ],
      )
      output = subject.map(input, to: Array)

      expect(output).to eq([false])
    end
  end

  context "MachineState" do
    it "yields an id that's a symbol, not a string" do
      input = Hashicorp::Vagrant::Sdk::Args::Target::Machine::State.new(
        id: "running",
      )
      output = subject.map(input, to: Vagrant::MachineState)

      expect(output.id).to eq(:running)
    end
  end
end