Skip to content

Commit

Permalink
chore: add ut for meminfo.go, update codecov.yaml (#208)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed Jun 6, 2022
1 parent 49850ce commit 282342c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
30 changes: 21 additions & 9 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
flag_management:
default_rules:
carryforward: true
statuses:
- name_prefix: project-
type: project
coverage:
status:
project:
# global coverage
default:
target: auto
threshold: 5%
threshold: 2%
flags:
- unittests
paths:
- "pkg"
# advanced settings
if_ci_failed: error #success, failure, error, ignore
if_no_uploads: error
if_not_found: success # no commit found? still set a success
- name_prefix: patch-
type: patch
patch:
# diff coverage
default:
target: 70%
flags:
- unittests
paths:
- "pkg"
if_ci_failed: error
if_no_uploads: success
if_not_found: success

github_checks:
annotations: true
67 changes: 64 additions & 3 deletions pkg/util/meminfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,26 @@ func Test_readMemInfo(t *testing.T) {
"HugePages_Rsvd: 0\nHugePages_Surp: 0\nHugepagesize: 2048 kB\n" +
"DirectMap4k: 414760 kB\nDirectMap2M: 8876032 kB\nDirectMap1G: 261095424 kB\n"
err := ioutil.WriteFile(tempMemInfoPath, []byte(memInfoContentStr), 0666)
if err != nil {
t.Error(err)
}
assert.NoError(t, err)
tempMemInfoPath1 := filepath.Join(tempDir, "meminfo1")
memInfoContentStr1 := "MemTotal: 263432804 kB\nMemFree: 254391744 kB\nMemAvailable: 256703236 kB\n" +
"Buffers: 958096 kB\nCached: invalidField kB\nSwapCached: 0 kB\n" +
"Active: 2786012 kB\nInactive: 2223752 kB\nActive(anon): 289488 kB\n" +
"Inactive(anon): 1300 kB\nActive(file): 2496524 kB\nInactive(file): 2222452 kB\n" +
"Unevictable: 0 kB\nMlocked: 0 kB\nSwapTotal: 0 kB\n" +
"SwapFree: 0 kB\nDirty: 624 kB\nWriteback: 0 kB\n" +
"AnonPages: 281748 kB\nMapped: 495936 kB\nShmem: 2340 kB\n" +
"Slab: 1097040 kB\nSReclaimable: 445164 kB\nSUnreclaim: 651876 kB\n" +
"KernelStack: 20944 kB\nPageTables: 7896 kB\nNFS_Unstable: 0 kB\n" +
"Bounce: 0 kB\nWritebackTmp: 0 kB\nCommitLimit: 131716400 kB\n" +
"Committed_AS: 3825364 kB\nVmallocTotal: 34359738367 kB\nVmallocUsed: 0 kB\n" +
"VmallocChunk: 0 kB\nHardwareCorrupted: 0 kB\nAnonHugePages: 38912 kB\n" +
"ShmemHugePages: 0 kB\nShmemPmdMapped: 0 kB\nCmaTotal: 0 kB\n" +
"CmaFree: 0 kB\nHugePages_Total: 0\nHugePages_Free: 0\n" +
"HugePages_Rsvd: 0\nHugePages_Surp: 0\nHugepagesize: 2048 kB\n" +
"DirectMap4k: 414760 kB\nDirectMap2M: 8876032 kB\nDirectMap1G: 261095424 kB\n"
err = ioutil.WriteFile(tempMemInfoPath1, []byte(memInfoContentStr1), 0666)
assert.NoError(t, err)
type args struct {
path string
}
Expand Down Expand Up @@ -89,6 +106,50 @@ func Test_readMemInfo(t *testing.T) {
},
wantErr: false,
},
{
name: "read test mem stat path",
args: args{path: tempMemInfoPath},
want: &MemInfo{
MemTotal: 263432804, MemFree: 254391744, MemAvailable: 256703236,
Buffers: 958096, Cached: 3763224, SwapCached: 0,
Active: 2786012, Inactive: 2223752, ActiveAnon: 289488,
InactiveAnon: 1300, ActiveFile: 2496524, InactiveFile: 2222452,
Unevictable: 0, Mlocked: 0, SwapTotal: 0,
SwapFree: 0, Dirty: 624, Writeback: 0,
AnonPages: 281748, Mapped: 495936, Shmem: 2340,
Slab: 1097040, SReclaimable: 445164, SUnreclaim: 651876,
KernelStack: 20944, PageTables: 7896, NFS_Unstable: 0,
Bounce: 0, WritebackTmp: 0, CommitLimit: 131716400,
Committed_AS: 3825364, VmallocTotal: 34359738367, VmallocUsed: 0,
VmallocChunk: 0, HardwareCorrupted: 0, AnonHugePages: 38912,
HugePages_Total: 0, HugePages_Free: 0, HugePages_Rsvd: 0,
HugePages_Surp: 0, Hugepagesize: 2048, DirectMap4k: 414760,
DirectMap2M: 8876032, DirectMap1G: 261095424,
},
wantErr: false,
},
{
name: "read test mem stat path",
args: args{path: tempMemInfoPath1},
want: &MemInfo{
MemTotal: 263432804, MemFree: 254391744, MemAvailable: 256703236,
Buffers: 958096, Cached: 0, SwapCached: 0,
Active: 2786012, Inactive: 2223752, ActiveAnon: 289488,
InactiveAnon: 1300, ActiveFile: 2496524, InactiveFile: 2222452,
Unevictable: 0, Mlocked: 0, SwapTotal: 0,
SwapFree: 0, Dirty: 624, Writeback: 0,
AnonPages: 281748, Mapped: 495936, Shmem: 2340,
Slab: 1097040, SReclaimable: 445164, SUnreclaim: 651876,
KernelStack: 20944, PageTables: 7896, NFS_Unstable: 0,
Bounce: 0, WritebackTmp: 0, CommitLimit: 131716400,
Committed_AS: 3825364, VmallocTotal: 34359738367, VmallocUsed: 0,
VmallocChunk: 0, HardwareCorrupted: 0, AnonHugePages: 38912,
HugePages_Total: 0, HugePages_Free: 0, HugePages_Rsvd: 0,
HugePages_Surp: 0, Hugepagesize: 2048, DirectMap4k: 414760,
DirectMap2M: 8876032, DirectMap1G: 261095424,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 282342c

Please sign in to comment.