Completed
Push — master ( ec4189...678e72 )
by kota
06:23
created

gost.TestParseCwe   A

Complexity

Conditions 4

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 18
dl 0
loc 26
rs 9.5
c 0
b 0
f 0
nop 1
1
package gost
2
3
import (
4
	"reflect"
5
	"sort"
6
	"testing"
7
)
8
9
func TestParseCwe(t *testing.T) {
10
	var tests = []struct {
11
		in  string
12
		out []string
13
	}{
14
		{
15
			in:  "CWE-665->(CWE-200|CWE-89)",
16
			out: []string{"CWE-665", "CWE-200", "CWE-89"},
17
		},
18
		{
19
			in:  "CWE-841->CWE-770->CWE-454",
20
			out: []string{"CWE-841", "CWE-770", "CWE-454"},
21
		},
22
		{
23
			in:  "(CWE-122|CWE-125)",
24
			out: []string{"CWE-122", "CWE-125"},
25
		},
26
	}
27
28
	r := RedHat{}
29
	for i, tt := range tests {
30
		out := r.parseCwe(tt.in)
31
		sort.Strings(out)
32
		sort.Strings(tt.out)
33
		if !reflect.DeepEqual(tt.out, out) {
34
			t.Errorf("[%d]expected: %s, actual: %s", i, tt.out, out)
35
		}
36
	}
37
}
38