Closed oliviabarnett closed 7 years ago
Instead of doing this hack with the global getProcCmdline
, why not change the code to call the getProcCmdline
once, add the cmd-line string to the Target
object, and test the target object in all the tests? Would also make the tests a lot easier because you wouldn't need the hack.
@oliviabarnett let me know if you need any help with the code. It was my first Go project and everything is a bit rough. Glad someone is contributing to this though :D
@zuBux we would love your review/help.
Merged the vndr branch. This one now needs a rebase!
Since cmd/actuary
is more library code, similar to oututils
and profileutils
, and we seem to be following the pattern where cmd
is for CLI stuff, perhaps we can move cmd/actuary
back to the top level, and have the cli stuff (in actuary.go
for instance) import from github.com/diogomonica/actuary/actuary
?
Agreed with @cyli on moving the code.
Still red on CircleCI!
LGTM
Tests split into 6 files.
Main methods of testing the functions:
Created a testTarget object that could be manipulated. Easy to use fake input to functions that request information only from the target parameter. (see dockerhost_test.go, dockerconf_test.go, images_test.go). Also used for all the functions that check container runtime settings -- could change testTarget's containers to either pass/fail for testing (see runtime_test.go)
/testdata folder holds fake files. Rewrote a lot of the hardcoded lines (ex. /etc/fstab) in check functions as variables so that I could run the functions on files within /testdata during testing only. Similarly, used a "changePath" function to force the functions to look for expected files in /testdata first. (see dockerhost_test.go, dockerfiles_test.go)
Mock server. Created a testServer function that handles calls to the docker API and returns fake data to the functions. (see dockerhost_test.go, runtime_test.go, secops_test.go)
Wrote a function that calls getProcCmdLine as a variable. For all the functions that call getProcCmdLine could replace with a different function call that returns fake data. (see dockerconf_test.go, dockerfiles_test.go)
Noted potential problems in comments. Most unfinished test functions are in runtime_test.go -- reasons are noted.
@diogomonica @cyli