package system

import (
	"fmt"
	"github.com/gookit/goutil/jsonutil"
	"path/filepath"
	"testing"
)

var i = &InfoUtils{}

func TestCpu(t *testing.T) {
	fmt.Println(i.GetCpuInfo())
}

func TestMemory(t *testing.T) {
	fmt.Println(i.GetVirtualMemory())
	fmt.Println(i.GetSwapMemory())
}

func TestDisk(t *testing.T) {
	partitions := i.GetDiskPartitions()
	fmt.Println(partitions)
	for _, partition := range partitions {
		fmt.Println(i.GetDiskUsage(partition.Device))
	}
	fmt.Println(i.GetIOCounters())
}

func TestNetwork(t *testing.T) {
	fmt.Println(i.GetNetWorkConnection())
}

func TestProcess(t *testing.T) {
	processList := i.GetAllProcessPid()
	for _, pid := range processList {
		fmt.Println(i.GetProcessInfo(pid))
	}
}

func TestScanDir(t *testing.T) {
	fmt.Println(filepath.IsAbs("E:"), filepath.IsAbs("E:/"))
	path, err := filepath.Abs("E:/")
	if err != nil {
		fmt.Println(err)
	}

	data, err := i.ScanDir(path)
	if err != nil {
		fmt.Println(err)
	}

	for _, entry := range data {
		str, _ := jsonutil.Encode(entry)
		fmt.Printf("%s\n", str)
	}
}
