summaryrefslogtreecommitdiff
path: root/tests/white-box/dummy.rb
blob: 6ca497549f2f42a65f0426caba9bbcf1c0b12219 (plain)
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
# only run in the dummy case where there is no hiera.yaml file.
raise SkipTest unless $node["dummy"]

class Robot
  def can_shoot_lasers?
    "OHAI!"
  end

  def can_fly?
    "YES!"
  end
end

class TestDummy < LeapTest
  def setup
    @robot = Robot.new
  end

  def test_lasers
    assert_equal "OHAI!", @robot.can_shoot_lasers?
    pass
  end

  def test_fly
    refute_match /^no/i, @robot.can_fly?
    pass
  end

  def test_fail
    fail "fail"
    pass
  end

  def test_01_will_be_skipped
    skip "test this later"
    pass
  end

  def test_socket_failure
    assert_tcp_socket('localhost', 900000)
    pass
  end

  def test_socket_success
    fork {
      Socket.tcp_server_loop('localhost', 12345) do |sock, client_addrinfo|
        begin
          sock.write('hi')
        ensure
          sock.close
          exit
        end
      end
    }
    sleep 0.2
    assert_tcp_socket('localhost', 12345)
    pass
  end

end