123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package gupta
- import (
- "fmt"
- "strings"
- "testing"
- )
- func TestFreeMem(t *testing.T) {
- m := Memory{}
- m.free = uint64(1200)
- got := m.Free()
- want := uint64(1200)
- name := "free"
- if got != want {
- t.Errorf("got %s %d want %d", name, got, want)
- }
- }
- func TestTotalMem(t *testing.T) {
- m := Memory{total: uint64(2400)}
- got := m.Total()
- want := uint64(2400)
- name := "total"
- if got != want {
- t.Errorf("got %s %d want %d", name, got, want)
- }
- }
- func TestUsedMem(t *testing.T) {
- m := Memory{total: uint64(2400), free: uint64(1200)}
- got := m.Used()
- fmt.Println(got)
- want := uint64(1200)
- name := "used"
- if got != want {
- t.Errorf("got %s %d want %d", name, got, want)
- }
- }
- func TestNewMemory(t *testing.T) {
- //r, _ := os.open("/proc/meminfo")
- r := strings.NewReader("MemTotal: 16080192 kB\nMemFree: 3617004 kB\nMemAvailable: 11258504 kB\nBuffers: 1814108 kB\n")
- mem := NewMemory(r)
- got := mem.total
- want := uint64(16080192)
- name := "memory total"
- if got != want {
- t.Errorf("got %s %d want %d", name, got, want)
- }
- }
|