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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
|
require "helper"
describe "platform" do
def mock_platform(x)
plat = Train::Platforms.name(x)
plat.family_hierarchy = mock_os_hierarchy(plat).flatten
plat.platform[:family] = plat.family_hierarchy[0]
plat.add_platform_methods
plat
end
def mock_platform_family(x)
Train::Platforms.list[x] = nil if x == "mock"
plat = Train::Platforms.name(x).in_family(x)
plat.family_hierarchy = mock_os_hierarchy(plat).flatten
plat.platform[:family] = plat.family_hierarchy[0]
plat.add_platform_methods
plat
end
def mock_os_hierarchy(plat)
plat.families.each_with_object([]) do |(k, _v), memo|
memo << k.name
memo << mock_os_hierarchy(k) unless k.families.empty?
end
end
it "set platform title" do
plat = mock_platform_family("mock")
_(plat.title).must_equal("Mock")
plat.title("The Best Mock")
_(plat.title).must_equal("The Best Mock")
end
it "clean init name" do
plat = mock_platform_family("Mo ck")
_(plat.name).must_equal("mo_ck")
end
it "set name and name override" do
plat = mock_platform_family("mock")
_(plat.name).must_equal("mock")
_(plat[:name]).must_equal("mock")
plat.platform[:name] = "Mock 2020"
plat.add_platform_methods
_(plat.name).must_equal("mock_2020")
_(plat[:name]).must_equal("mock_2020")
end
it "check families" do
plat = mock_platform_family("mock")
_(plat.families.keys[0].name).must_equal("mock")
end
it "check families with condition" do
Train::Platforms.list["mock"] = nil
plat = Train::Platforms.name("mock", arch: "= x86_64").in_family("linux")
_(plat.families.keys[0].name).must_equal("linux")
_(plat.families.values[0]).must_equal({ arch: "= x86_64" })
end
it "finds family hierarchy" do
plat = Train::Platforms.name("linux")
plat.find_family_hierarchy
_(plat.family_hierarchy).must_equal %w{linux unix os}
end
it "return direct families" do
plat = mock_platform_family("mock")
plat.in_family("mock2")
plat.in_family("mock3")
_(plat.direct_families).must_equal(%w{mock mock2 mock3})
end
it "return to_hash" do
plat = mock_platform_family("mock")
_(plat.to_hash).must_equal({ family: "mock" })
end
it "return unknown release" do
plat = mock_platform_family("mock")
_(plat[:release]).must_equal("unknown")
end
it "return name?" do
plat = Train::Platforms.name("windows_rc1")
_(defined?(plat.windows_rc1?)).must_be_nil
plat.add_platform_methods
_(plat.windows_rc1?).must_equal(true)
end
it "add platform methods" do
Train::Platforms.list["mock"] = nil
plat = Train::Platforms.name("mock").in_family("linux")
_(defined?(plat.linux?)).must_be_nil
plat.family_hierarchy = mock_os_hierarchy(plat).flatten
plat.add_platform_methods
_(plat.linux?).must_equal(true)
end
it "provides a method to access platform data" do
family = "test-os"
os = mock_platform_family(family)
_(os[:family]).must_equal family
end
it "provides an accessor for the full hash" do
x = "test-os"
os = mock_platform_family(x)
_(os.to_hash).must_equal({ family: x })
end
it "has a friendly #to_s and #inspect" do
plat = mock_platform("redhat")
_(plat.to_s).must_equal "Train::Platforms::Platform:unknown:redhat"
_(plat.inspect).must_equal "Train::Platforms::Platform:unknown:redhat"
end
describe "with platform set to redhat" do
let(:os) { mock_platform("redhat") }
it { _(os.redhat?).must_equal(true) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to oracle" do
let(:os) { mock_platform("oracle") }
it { _(os.redhat?).must_equal(true) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to centos" do
let(:os) { mock_platform("centos") }
it { _(os.redhat?).must_equal(true) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to cloudlinux" do
let(:os) { mock_platform("cloudlinux") }
it { _(os.redhat?).must_equal(true) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to fedora" do
let(:os) { mock_platform("fedora") }
it { _(os.fedora?).must_equal(true) }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to amazon" do
let(:os) { mock_platform("amazon") }
it { _(os.fedora?).must_equal(false) }
it { _(os.redhat?).must_equal(true) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to debian" do
let(:os) { mock_platform("debian") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(true) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to ubuntu" do
let(:os) { mock_platform("ubuntu") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(true) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to linuxmint" do
let(:os) { mock_platform("linuxmint") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(true) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to raspbian" do
let(:os) { mock_platform("raspbian") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(true) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to suse" do
let(:os) { mock_platform("suse") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(true) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to opensuse" do
let(:os) { mock_platform("opensuse") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(true) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to alpine" do
let(:os) { mock_platform("alpine") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to arch" do
let(:os) { mock_platform("arch") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to coreos" do
let(:os) { mock_platform("coreos") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to exherbo" do
let(:os) { mock_platform("exherbo") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to gentoo" do
let(:os) { mock_platform("gentoo") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to slackware" do
let(:os) { mock_platform("slackware") }
it { _(os.redhat?).must_equal(false) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to wrlinux" do
let(:os) { mock_platform("wrlinux") }
it { _(os.redhat?).must_equal(true) }
it { _(os.debian?).must_equal(false) }
it { _(os.suse?).must_equal(false) }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to linux" do
let(:os) { mock_platform("linux") }
it { _(os.linux?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to freebsd" do
let(:os) { mock_platform("freebsd") }
it { _(os.bsd?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to netbsd" do
let(:os) { mock_platform("netbsd") }
it { _(os.bsd?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to openbsd" do
let(:os) { mock_platform("openbsd") }
it { _(os.bsd?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to darwin" do
let(:os) { mock_platform("darwin") }
it { _(os.bsd?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to solaris" do
let(:os) { mock_platform("solaris") }
it { _(os.solaris?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to smartos" do
let(:os) { mock_platform("smartos") }
it { _(os.solaris?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to openindiana" do
let(:os) { mock_platform("openindiana") }
it { _(os.solaris?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to opensolaris" do
let(:os) { mock_platform("opensolaris") }
it { _(os.solaris?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to nexentacore" do
let(:os) { mock_platform("nexentacore") }
it { _(os.solaris?).must_equal(true) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
end
describe "with platform set to windows" do
let(:os) { mock_platform("windows") }
it { _(os.solaris?).must_equal(false) }
it { _(os.bsd?).must_equal(false) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(false) }
end
describe "with platform set to hpux" do
let(:os) { mock_platform("hpux") }
it { _(os.solaris?).must_equal(false) }
it { _(os.linux?).must_equal(false) }
it { _(os.unix?).must_equal(true) }
it { _(os.hpux?).must_equal(true) }
end
describe "with platform set to esx" do
let(:os) { mock_platform("vmkernel") }
it { _(os.solaris?).must_equal(false) }
it { _(os.linux?).must_equal(false) }
it { _(os[:family]).must_equal("esx") }
it { _(os.unix?).must_equal(false) }
it { _(os.esx?).must_equal(true) }
end
describe "with platform set to darwin" do
let(:os) { mock_platform("darwin") }
it { _(os.solaris?).must_equal(false) }
it { _(os.linux?).must_equal(false) }
it { _(os[:family]).must_equal("darwin") }
it { _(os.bsd?).must_equal(true) }
it { _(os.darwin?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
it { _(os.bsd?).must_equal(true) }
it { _(os.esx?).must_equal(false) }
end
describe "with platform set to mac_os_x" do
let(:os) { mock_platform("mac_os_x") }
it { _(os.solaris?).must_equal(false) }
it { _(os.linux?).must_equal(false) }
it { _(os[:family]).must_equal("darwin") }
it { _(os.bsd?).must_equal(true) }
it { _(os.darwin?).must_equal(true) }
it { _(os.unix?).must_equal(true) }
it { _(os.bsd?).must_equal(true) }
it { _(os.esx?).must_equal(false) }
end
end
|