~ubuntu-branches/ubuntu/wily/puppet/wily

« back to all changes in this revision

Viewing changes to spec/unit/network/formats_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2014-04-17 14:50:28 UTC
  • mfrom: (3.1.59 sid)
  • Revision ID: package-import@ubuntu.com-20140417145028-j3p3dwvp8ggpzvaf
Tags: 3.5.1-1
ImportedĀ upstreamĀ releaseĀ 3.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    string == other.string
10
10
  end
11
11
 
12
 
  def self.from_pson(data)
 
12
  def self.from_data_hash(data)
13
13
    new(data)
14
14
  end
15
15
 
43
43
      @msgpack.weight.should == 20
44
44
    end
45
45
 
46
 
    it "should fail when one element does not have a from_pson" do
 
46
    it "should fail when one element does not have a from_data_hash" do
47
47
      expect do
48
48
        @msgpack.intern_multiple(Hash, MessagePack.pack(["foo"]))
49
49
      end.to raise_error(NoMethodError)
50
50
    end
 
51
 
 
52
    it "should be able to serialize a catalog" do
 
53
      cat = Puppet::Resource::Catalog.new('foo')
 
54
      cat.add_resource(Puppet::Resource.new(:file, 'my_file'))
 
55
      catunpack = MessagePack.unpack(cat.to_msgpack)
 
56
      catunpack.should include(
 
57
        "tags"=>[],
 
58
        "name"=>"foo",
 
59
        "version"=>nil,
 
60
        "environment"=>"",
 
61
        "edges"=>[],
 
62
        "classes"=>[]
 
63
      )
 
64
      catunpack["resources"][0].should include(
 
65
        "type"=>"File",
 
66
        "title"=>"my_file",
 
67
        "exported"=>false
 
68
      )
 
69
      catunpack["resources"][0]["tags"].should include(
 
70
        "file",
 
71
        "my_file"
 
72
      )
 
73
    end
51
74
  end
52
75
 
53
76
  it "should include a yaml format" do
293
316
        @pson.render_multiple(instances).should == "foo"
294
317
      end
295
318
 
296
 
      it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the data into an instance" do
 
319
      it "should intern by calling 'PSON.parse' on the text and then using from_data_hash to convert the data into an instance" do
297
320
        text = "foo"
298
321
        PSON.expects(:parse).with("foo").returns("type" => "PsonTest", "data" => "foo")
299
 
        PsonTest.expects(:from_pson).with("foo").returns "parsed_pson"
 
322
        PsonTest.expects(:from_data_hash).with("foo").returns "parsed_pson"
300
323
        @pson.intern(PsonTest, text).should == "parsed_pson"
301
324
      end
302
325
 
304
327
        text = "foo"
305
328
        instance = PsonTest.new("foo")
306
329
        PSON.expects(:parse).with("foo").returns(instance)
307
 
        PsonTest.expects(:from_pson).never
 
330
        PsonTest.expects(:from_data_hash).never
308
331
        @pson.intern(PsonTest, text).should equal(instance)
309
332
      end
310
333
 
311
 
      it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the actual into an instance if the pson has no class/data separation" do
 
334
      it "should intern by calling 'PSON.parse' on the text and then using from_data_hash to convert the actual into an instance if the pson has no class/data separation" do
312
335
        text = "foo"
313
336
        PSON.expects(:parse).with("foo").returns("foo")
314
 
        PsonTest.expects(:from_pson).with("foo").returns "parsed_pson"
 
337
        PsonTest.expects(:from_data_hash).with("foo").returns "parsed_pson"
315
338
        @pson.intern(PsonTest, text).should == "parsed_pson"
316
339
      end
317
340
 
318
341
      it "should intern multiples by parsing the text and using 'class.intern' on each resulting data structure" do
319
342
        text = "foo"
320
343
        PSON.expects(:parse).with("foo").returns ["bar", "baz"]
321
 
        PsonTest.expects(:from_pson).with("bar").returns "BAR"
322
 
        PsonTest.expects(:from_pson).with("baz").returns "BAZ"
 
344
        PsonTest.expects(:from_data_hash).with("bar").returns "BAR"
 
345
        PsonTest.expects(:from_data_hash).with("baz").returns "BAZ"
323
346
        @pson.intern_multiple(PsonTest, text).should == %w{BAR BAZ}
324
347
      end
325
348