#include <doctest/doctest.h>

#include "fgc/HostMetrics.h"

using namespace fgc::hostmetrics;

TEST_CASE("parseMeminfo extracts totals and swap usage") {
    const char* meminfo =
        "MemTotal:       16384000 kB\n"
        "MemFree:         2000000 kB\n"
        "MemAvailable:    8192000 kB\n"
        "Buffers:          100000 kB\n"
        "SwapTotal:       2048000 kB\n"
        "SwapFree:        1024000 kB\n";
    MemInfo m = parseMeminfo(meminfo);
    CHECK(m.ok);
    CHECK(m.total_mb == doctest::Approx(16384000.0 / 1024.0));
    CHECK(m.avail_mb == doctest::Approx(8192000.0 / 1024.0));
    CHECK(m.swap_used_mb == doctest::Approx((2048000.0 - 1024000.0) / 1024.0));
}

TEST_CASE("parseMeminfo: missing fields => not ok") {
    MemInfo m = parseMeminfo("MemFree: 100 kB\n");
    CHECK_FALSE(m.ok);
}

TEST_CASE("parseMilliCelsius converts sysfs milli-degrees") {
    CHECK(parseMilliCelsius("52000\n") == doctest::Approx(52.0));
    CHECK(parseMilliCelsius("") == doctest::Approx(0.0));
}

TEST_CASE("readDisk on the working tree returns sane values") {
    DiskInfo d = readDisk(".");
    CHECK(d.ok);
    CHECK(d.total_gb > 0.0);
    CHECK(d.used_pct >= 0.0);
    CHECK(d.used_pct <= 100.0);
}
