MCPcopy Index your code
hub / github.com/coder/coder / TestFetchMemory

Function TestFetchMemory

agent/proto/resourcesmonitor/fetcher_test.go:41–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestFetchMemory(t *testing.T) {
42 t.Parallel()
43
44 t.Run("IsContainerized", func(t *testing.T) {
45 t.Parallel()
46
47 t.Run("WithMemoryLimit", func(t *testing.T) {
48 t.Parallel()
49
50 fetcher, err := resourcesmonitor.NewFetcher(&mockStatter{
51 isContainerized: true,
52 containerMemory: clistat.Result{
53 Used: 10.0,
54 Total: ptr.Ref(20.0),
55 },
56 hostMemory: clistat.Result{
57 Used: 20.0,
58 Total: ptr.Ref(30.0),
59 },
60 })
61 require.NoError(t, err)
62
63 total, used, err := fetcher.FetchMemory()
64 require.NoError(t, err)
65 require.Equal(t, int64(10), used)
66 require.Equal(t, int64(20), total)
67 })
68
69 t.Run("WithoutMemoryLimit", func(t *testing.T) {
70 t.Parallel()
71
72 fetcher, err := resourcesmonitor.NewFetcher(&mockStatter{
73 isContainerized: true,
74 containerMemory: clistat.Result{
75 Used: 10.0,
76 Total: nil,
77 },
78 hostMemory: clistat.Result{
79 Used: 20.0,
80 Total: ptr.Ref(30.0),
81 },
82 })
83 require.NoError(t, err)
84
85 total, used, err := fetcher.FetchMemory()
86 require.NoError(t, err)
87 require.Equal(t, int64(10), used)
88 require.Equal(t, int64(30), total)
89 })
90 })
91
92 t.Run("IsHost", func(t *testing.T) {
93 t.Parallel()
94
95 fetcher, err := resourcesmonitor.NewFetcher(&mockStatter{
96 isContainerized: false,
97 hostMemory: clistat.Result{
98 Used: 20.0,

Callers

nothing calls this directly

Calls 5

FetchMemoryMethod · 0.95
NewFetcherFunction · 0.92
RefFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected