~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/unit/util/network_device/transport/telnet_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env rspec
 
2
 
 
3
require File.dirname(__FILE__) + '/../../../../spec_helper'
 
4
 
 
5
require 'puppet/util/network_device/transport/telnet'
 
6
 
 
7
describe Puppet::Util::NetworkDevice::Transport::Telnet do
 
8
 
 
9
  before(:each) do
 
10
    @transport = Puppet::Util::NetworkDevice::Transport::Telnet.new()
 
11
  end
 
12
 
 
13
  it "should not handle login through the transport" do
 
14
    @transport.should_not be_handles_login
 
15
  end
 
16
 
 
17
  it "should connect to the given host and port" do
 
18
    Net::Telnet.expects(:new).with { |args| args["Host"] == "localhost" && args["Port"] == 23 }.returns stub_everything
 
19
    @transport.host = "localhost"
 
20
    @transport.port = 23
 
21
 
 
22
    @transport.connect
 
23
  end
 
24
 
 
25
  it "should connect and specify the default prompt" do
 
26
    @transport.default_prompt = "prompt"
 
27
    Net::Telnet.expects(:new).with { |args| args["Prompt"] == "prompt" }.returns stub_everything
 
28
    @transport.host = "localhost"
 
29
    @transport.port = 23
 
30
 
 
31
    @transport.connect
 
32
  end
 
33
 
 
34
  describe "when connected" do
 
35
    before(:each) do
 
36
      @telnet = stub_everything 'telnet'
 
37
      Net::Telnet.stubs(:new).returns(@telnet)
 
38
      @transport.connect
 
39
    end
 
40
 
 
41
    it "should send line to the telnet session" do
 
42
      @telnet.expects(:puts).with("line")
 
43
      @transport.send("line")
 
44
    end
 
45
 
 
46
    describe "when expecting output" do
 
47
      it "should waitfor output on the telnet session" do
 
48
        @telnet.expects(:waitfor).with(/regex/)
 
49
        @transport.expect(/regex/)
 
50
      end
 
51
 
 
52
      it "should return telnet session output" do
 
53
        @telnet.expects(:waitfor).returns("output")
 
54
        @transport.expect(/regex/).should == "output"
 
55
      end
 
56
 
 
57
      it "should yield telnet session output to the given block" do
 
58
        @telnet.expects(:waitfor).yields("output")
 
59
        @transport.expect(/regex/) { |out| out.should == "output" }
 
60
      end
 
61
    end
 
62
  end
 
63
 
 
64
  describe "when closing" do
 
65
    before(:each) do
 
66
      @telnet = stub_everything 'telnet'
 
67
      Net::Telnet.stubs(:new).returns(@telnet)
 
68
      @transport.connect
 
69
    end
 
70
 
 
71
    it "should close the telnet session" do
 
72
      @telnet.expects(:close)
 
73
      @transport.close
 
74
    end
 
75
  end
 
76
end