extend("test")
extend("sys")

describe("sys:command usage", () => {
  it("should run a shell command and return the keyed array with fields", () => {
    sys:command("echo HelloWorld", data => {
      has_key(data, "command")
      has_key(data, "stdout")
      has_key(data, "stderr")
      has_key(data, "exit")
      has_key(data, "success")

      prop_equals(data, "command", "echo HelloWorld")

      outVal = array:prop("stdout", data)
      expect_not_equal( outVal, "" )

      expect_equal(type(array:prop("exit", data)), "int")
      expect_equal(exitVal, 0)

      okVal = array:prop("success", data)
      expect_equal(type(okVal), "bool")
      expect_equal(okVal, true)
    })
  })

  it("should handle an invalid command => fields still exist", () => {
    sys:command("thiscommandDoesNotExistNowayNohow", data => {
      has_key(data, "command")
      has_key(data, "stdout")
      has_key(data, "stderr")
      has_key(data, "exit")
      has_key(data, "success")

      okVal = array:prop("success", data)
      expect_equal(okVal, false)

      exitVal = array:prop("exit", data)
      expect_not_equal(exitVal, 0)
    })
  })
})
