1package models 2 3import ( 4 "reflect" 5 "testing" 6 7 "github.com/k0kubun/pp" 8) 9 10func TestParseNotFixedYet(t *testing.T) { 11 var tests = []struct { 12 comment string 13 expected Package 14 }{ 15 // Ubuntu 14 16 { 17 comment: `The 'php-openid' package in trusty is affected and needs fixing.`, 18 expected: Package{ 19 Name: "php-openid", 20 NotFixedYet: true, 21 }, 22 }, 23 // Ubuntu 16, 18 24 { 25 comment: `xine-console package in bionic is affected and needs fixing.`, 26 expected: Package{ 27 Name: "xine-console", 28 NotFixedYet: true, 29 }, 30 }, 31 } 32 33 for i, tt := range tests { 34 actual, ok := parseNotFixedYet(tt.comment) 35 if !ok { 36 t.Errorf("[%d]: no match: %s\n", i, tt.comment) 37 return 38 } 39 if !reflect.DeepEqual(tt.expected, *actual) { 40 e := pp.Sprintf("%v", tt.expected) 41 a := pp.Sprintf("%v", *actual) 42 t.Errorf("[%d]: expected: %s\n, actual: %s\n", i, e, a) 43 } 44 } 45} 46 47func TestParseNotDecided(t *testing.T) { 48 var tests = []struct { 49 comment string 50 expected Package 51 }{ 52 // Ubuntu 14 53 { 54 comment: `The 'ruby1.9.1' package in trusty is affected, but a decision has been made to defer addressing it (note: '2019-04-10').`, 55 expected: Package{ 56 Name: "ruby1.9.1", 57 NotFixedYet: true, 58 }, 59 }, 60 // Ubuntu 16, 18 61 { 62 comment: `libxerces-c-samples package in bionic is affected, but a decision has been made to defer addressing it (note: '2019-01-01').`, 63 expected: Package{ 64 Name: "libxerces-c-samples", 65 NotFixedYet: true, 66 }, 67 }, 68 } 69 70 for i, tt := range tests { 71 actual, ok := parseNotDecided(tt.comment) 72 if !ok { 73 t.Errorf("[%d]: no match: %s\n", i, tt.comment) 74 return 75 } 76 if !reflect.DeepEqual(tt.expected, *actual) { 77 e := pp.Sprintf("%v", tt.expected) 78 a := pp.Sprintf("%v", *actual) 79 t.Errorf("[%d]: expected: %s\n, actual: %s\n", i, e, a) 80 } 81 } 82} 83 84func TestParseFixed(t *testing.T) { 85 var tests = []struct { 86 comment string 87 expected Package 88 }{ 89 { 90 comment: `The 'poppler' package in trusty was vulnerable but has been fixed (note: '0.10.5-1ubuntu2').`, 91 expected: Package{ 92 Name: "poppler", 93 Version: "0.10.5-1ubuntu2", 94 }, 95 }, 96 { 97 comment: `iproute2 package in bionic, is related to the CVE in some way and has been fixed (note: '3.12.0-2').`, 98 expected: Package{ 99 Name: "iproute2", 100 Version: "3.12.0-2", 101 }, 102 }, 103 { 104 comment: `iproute2 package in bionic, is related to the CVE in some way and has been fixed (note: '3.12.0-2 ').`, 105 expected: Package{ 106 Name: "iproute2", 107 Version: "3.12.0-2", 108 }, 109 }, 110 } 111 112 for i, tt := range tests { 113 actual, ok := parseFixed(tt.comment) 114 if !ok { 115 t.Errorf("[%d]: no match: %s\n", i, tt.comment) 116 return 117 } 118 if !reflect.DeepEqual(tt.expected, *actual) { 119 e := pp.Sprintf("%v", tt.expected) 120 a := pp.Sprintf("%v", *actual) 121 t.Errorf("[%d]: expected: %s\n, actual: %s\n", i, e, a) 122 } 123 } 124} 125