From e3de4db85b0b537194cbfff4f469cb89e8e258b1 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 11 Mar 2022 03:30:06 -0500 Subject: add cvss/calc_test.go --- cvss/calc_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cvss/calc_test.go diff --git a/cvss/calc_test.go b/cvss/calc_test.go new file mode 100644 index 0000000..b47d9da --- /dev/null +++ b/cvss/calc_test.go @@ -0,0 +1,29 @@ +package cvss + +import "testing" + +func TestCalc(t *testing.T) { + tests := []struct { + val string + exp bool + } { + { "foo", false }, + { "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:N/A:N", true }, + } + + for _, test := range(tests) { + t.Run(test.val, func(t *testing.T) { + got := Calc([]string { test.val }) + if len(got) != 1 { + t.Errorf("invalid len(got): %d != 1", len(got)) + return + } + + if test.exp && got[0].Error != "" { + t.Errorf("got %s, exp success", got[0].Error) + } else if !test.exp && got[0].Error == "" { + t.Errorf("got %v, exp error", got[0]) + } + }) + } +} -- cgit v1.2.3