diogomonica / actuary

An actuary is a business professional who analyzes the financial consequences of risk.
78 stars 14 forks source link

Added tests for actuary code #31

Closed oliviabarnett closed 7 years ago

oliviabarnett commented 7 years ago

Tests split into 6 files.

Main methods of testing the functions:

  1. 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)

  2. /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)

  3. 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)

  4. 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

diogomonica commented 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.

zuBux commented 7 years ago

@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

diogomonica commented 7 years ago

@zuBux we would love your review/help.

diogomonica commented 7 years ago

Merged the vndr branch. This one now needs a rebase!

cyli commented 7 years ago

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?

diogomonica commented 7 years ago

Agreed with @cyli on moving the code.

diogomonica commented 7 years ago

Still red on CircleCI!

diogomonica commented 7 years ago

LGTM