PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/trema/link_spec.rb

http://github.com/trema/trema
Ruby | 64 lines | 27 code | 14 blank | 23 comment | 0 complexity | 5704a3910f7576fd5cc32b516c10462b MD5 | raw file
Possible License(s): GPL-2.0
  1. #
  2. # Author: Yasuhito Takamiya <yasuhito@gmail.com>
  3. #
  4. # Copyright (C) 2008-2012 NEC Corporation
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License, version 2, as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. #
  19. require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
  20. require "trema/link"
  21. module Trema
  22. describe Link do
  23. before :each do
  24. Trema::Link.instances.clear
  25. @stanza = mock( "link stanza", :peers => [ "Virtual Host", "Virtual Switch" ] )
  26. end
  27. context "when creating/deleting a link" do
  28. before :each do
  29. @link = Link.new( @stanza )
  30. end
  31. it "executes ip and ifconfig command" do
  32. @link.should_receive( :sh ).once.ordered.with( "sudo ip link add name trema0-0 type veth peer name trema0-1" )
  33. @link.should_receive( :sh ).once.ordered.with( "sudo sysctl -w net.ipv6.conf.trema0-0.disable_ipv6=1 >/dev/null 2>&1" )
  34. @link.should_receive( :sh ).once.ordered.with( "sudo sysctl -w net.ipv6.conf.trema0-1.disable_ipv6=1 >/dev/null 2>&1" )
  35. @link.should_receive( :sh ).once.ordered.with( "sudo /sbin/ifconfig trema0-0 up" )
  36. @link.should_receive( :sh ).once.ordered.with( "sudo /sbin/ifconfig trema0-1 up" )
  37. @link.enable!
  38. end
  39. it "executes ip and ifconfig command" do
  40. @link.should_receive( :sh ).once.with( "sudo ip link delete trema0-0 2>/dev/null" )
  41. @link.delete!
  42. end
  43. end
  44. end
  45. end
  46. ### Local variables:
  47. ### mode: Ruby
  48. ### coding: utf-8-unix
  49. ### indent-tabs-mode: nil
  50. ### End: