aboutsummaryrefslogtreecommitdiff
path: root/cvss/calc_test.go
blob: b47d9da3034419aeb8542de0c8e766853af3e023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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])
      }
    })
  }
}