| | 34 | fixtures :devices, :ipv4_networks, :l2_interfaces, :l3_interfaces |
|---|
| | 35 | |
|---|
| | 36 | |
|---|
| | 37 | # Test the link_to_controller function |
|---|
| | 38 | |
|---|
| | 39 | def test_link_to_controller |
|---|
| | 40 | |
|---|
| | 41 | # TODO: Write tests for link_to_controller |
|---|
| | 42 | |
|---|
| | 43 | end |
|---|
| | 44 | |
|---|
| | 45 | |
|---|
| | 46 | # Test the device_information_box function |
|---|
| | 47 | |
|---|
| | 48 | def test_device_information_box |
|---|
| | 49 | |
|---|
| | 50 | # TODO: Write tests for device_information_box |
|---|
| | 51 | |
|---|
| | 52 | end |
|---|
| | 53 | |
|---|
| | 54 | |
|---|
| | 55 | # Test the ipv4_network_name function |
|---|
| | 56 | |
|---|
| | 57 | def test_ipv4_network_name |
|---|
| | 58 | |
|---|
| | 59 | assert(ipv4_network_name("10.0.0.0") == "RFC1918 network 10.0.0.0/8") |
|---|
| | 60 | assert(ipv4_network_name(nil) == "Unknown") |
|---|
| | 61 | assert(ipv4_network_name("255.255.255.255") == "Unknown") |
|---|
| | 62 | |
|---|
| | 63 | end |
|---|
| | 64 | |
|---|
| | 65 | |
|---|
| | 66 | # Test the generate_title_line_1 function |
|---|
| | 67 | |
|---|
| | 68 | def test_generate_title_line_1 |
|---|
| | 69 | |
|---|
| | 70 | assert_equal "NetHorus Test", generate_title_line_1 |
|---|
| | 71 | |
|---|
| | 72 | end |
|---|
| | 73 | |
|---|
| | 74 | |
|---|
| | 75 | # Test the generate_title_line_2 function |
|---|
| | 76 | |
|---|
| | 77 | def test_generate_title_line_2 |
|---|
| | 78 | |
|---|
| | 79 | # TODO: Write a test for @subtitle = nil |
|---|
| | 80 | |
|---|
| | 81 | @subtitle = "foobar" |
|---|
| | 82 | assert_equal "foobar", generate_title_line_2 |
|---|
| | 83 | |
|---|
| | 84 | @subtitle = "" |
|---|
| | 85 | assert_equal "", generate_title_line_2 |
|---|
| | 86 | |
|---|
| | 87 | end |
|---|
| | 88 | |
|---|
| | 89 | |
|---|
| | 90 | # Test the generate_title_tag function |
|---|
| | 91 | |
|---|
| | 92 | def test_generate_title_tag |
|---|
| | 93 | |
|---|
| | 94 | @subtitle = "foobar" |
|---|
| | 95 | |
|---|
| | 96 | assert_equal "NetHorus Test: foobar", generate_title_tag |
|---|
| | 97 | |
|---|
| | 98 | end |
|---|
| | 99 | |
|---|
| | 100 | |
|---|
| | 101 | # Test the display_snmptable_value function |
|---|
| | 102 | |
|---|
| | 103 | def test_display_snmptable_value |
|---|
| | 104 | |
|---|
| | 105 | table = Hash.new |
|---|
| | 106 | table_data = Hash.new |
|---|
| | 107 | table_data[1] = "1:1" |
|---|
| | 108 | table[1] = table_data |
|---|
| | 109 | |
|---|
| | 110 | assert(display_snmptable_value(table, 1, 1) == "1:1") |
|---|
| | 111 | assert(display_snmptable_value(table, 1, 2) == "?") |
|---|
| | 112 | assert(display_snmptable_value(table, 2, 2) == "?") |
|---|
| | 113 | |
|---|
| | 114 | assert(display_snmptable_value(table, 1, nil) == "?") |
|---|
| | 115 | assert(display_snmptable_value(table, nil, 1) == "?") |
|---|
| | 116 | assert(display_snmptable_value(table, nil, nil) == "?") |
|---|
| | 117 | |
|---|
| | 118 | assert(display_snmptable_value(nil, 1, 1) == "?") |
|---|
| | 119 | assert(display_snmptable_value(nil, nil, 1) == "?") |
|---|
| | 120 | assert(display_snmptable_value(nil, 1, nil) == "?") |
|---|
| | 121 | assert(display_snmptable_value(nil, nil, nil) == "?") |
|---|
| | 122 | |
|---|
| | 123 | end |
|---|
| | 124 | |
|---|
| | 125 | |
|---|
| | 126 | # Test the display_yn function |
|---|
| | 127 | |
|---|
| | 128 | def test_display_yn |
|---|
| | 129 | |
|---|
| | 130 | assert(display_yn(nil) == "No") |
|---|
| | 131 | assert(display_yn("") == "No") |
|---|
| | 132 | assert(display_yn("foobar") == "No") |
|---|
| | 133 | assert(display_yn(:false) == "No") |
|---|
| | 134 | |
|---|
| | 135 | assert(display_yn(:true) == "Yes") |
|---|
| | 136 | |
|---|
| | 137 | end |
|---|
| | 138 | |
|---|
| | 139 | |
|---|
| | 140 | # Test the format_interface_name function |
|---|
| | 141 | |
|---|
| | 142 | def test_format_interface_name |
|---|
| | 143 | |
|---|
| | 144 | assert(format_interface_name("Foo", "Bar") == "Foo (Bar)") |
|---|
| | 145 | assert(format_interface_name("Foo", "") == "Foo") |
|---|
| | 146 | |
|---|
| | 147 | assert(format_interface_name("", "Bar") == "") |
|---|
| | 148 | assert(format_interface_name("", "") == "") |
|---|
| | 149 | |
|---|
| | 150 | assert(format_interface_name("Foo", nil) == "Foo") |
|---|
| | 151 | assert(format_interface_name(nil, "Bar") == "") |
|---|
| | 152 | |
|---|
| | 153 | assert(format_interface_name(nil, nil) == "") |
|---|
| | 154 | |
|---|
| | 155 | end |
|---|
| | 156 | |
|---|
| | 157 | |
|---|
| | 158 | # Test the format_l2_interface function |
|---|
| | 159 | |
|---|
| | 160 | def test_format_l2_interface |
|---|
| | 161 | |
|---|
| | 162 | assert(format_l2_interface("something") == "something") |
|---|
| | 163 | assert(format_l2_interface("") == "none") |
|---|
| | 164 | assert(format_l2_interface(nil) == "none") |
|---|
| | 165 | |
|---|
| | 166 | end |
|---|
| | 167 | |
|---|
| | 168 | |
|---|
| | 169 | # Test the format_l2_interface_type function |
|---|
| | 170 | |
|---|
| | 171 | def test_format_l2_interface_type |
|---|
| | 172 | |
|---|
| | 173 | assert(format_l2_interface_type("something") == "something") |
|---|
| | 174 | assert(format_l2_interface_type("") == "Unknown") |
|---|
| | 175 | assert(format_l2_interface_type(nil) == "Unknown") |
|---|
| | 176 | |
|---|
| | 177 | end |
|---|
| | 178 | |
|---|
| | 179 | |
|---|
| | 180 | # Test the format_l3_interface function |
|---|
| | 181 | |
|---|
| | 182 | def test_format_l3_interface |
|---|
| | 183 | |
|---|
| | 184 | example_interface = l2_interfaces(:test_l2interface_1) |
|---|
| | 185 | assert(format_l3_interface(example_interface) == "10.0.0.1 (RFC1918 network 10.0.0.0/8)") |
|---|
| | 186 | |
|---|
| | 187 | example_interface_without_children = l2_interfaces(:l2_interface_without_any_l3_interfaces) |
|---|
| | 188 | assert(format_l3_interface(example_interface_without_children) == "none") |
|---|
| | 189 | |
|---|
| | 190 | end |
|---|
| | 191 | |
|---|