-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpartmaster_test.go
More file actions
45 lines (36 loc) · 941 Bytes
/
partmaster_test.go
File metadata and controls
45 lines (36 loc) · 941 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"testing"
"github.com/gocarina/gocsv"
)
var pmIn = `
IPN,Description,Value,Manufacturer,MPN,Priority
CAP-001-1001,superduper cap,,CapsInc,10045,2
CAP-001-1001,,10k,MaxCaps,abc2322,1
CAP-001-1002,,,MaxCaps,abc2323,
`
func TestPartmaster(t *testing.T) {
initCSV()
pm := partmaster{}
err := gocsv.UnmarshalBytes([]byte(pmIn), &pm)
if err != nil {
t.Fatalf("Error parsing pmIn: %v", err)
}
p, err := pm.findPart("CAP-001-1001")
if err != nil {
t.Fatalf("Error finding part CAP-001-1001: %v", err)
}
if p.MPN != "abc2322" {
t.Errorf("Got wrong part for CAP-001-1001, %v", p.MPN)
}
if p.Description != "superduper cap" {
t.Errorf("Got wrong description for CAP-001-1001: %v", p.Description)
}
if p.Value != "10k" {
t.Errorf("Got wrong value for CAP-001-1001: %v", p.Value)
}
_, err = pm.findPart("CAP-001-1002")
if err != nil {
t.Fatalf("Error finding part CAP-001-1002: %v", err)
}
}