-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_records.go
38 lines (34 loc) · 872 Bytes
/
test_records.go
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
package gotestfast
import (
"encoding/json"
"os"
)
func rearrangeTestRecords(previous, current TestRecords) TestRecords {
uniqueKeys := make(map[string]struct{}, len(previous))
for _, record := range previous {
key := record.Package + "/" + record.Name
uniqueKeys[key] = struct{}{}
}
result := make(TestRecords, 0, len(previous)+len(current))
for _, record := range current {
key := record.Package + "/" + record.Name
if _, ok := uniqueKeys[key]; !ok {
result = append(result, record)
}
}
result = append(result, previous...)
return result
}
func ReadRecordFile(filePath string) (TestRecords, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, nil
}
defer file.Close()
var records TestRecords
decoder := json.NewDecoder(file)
if err := decoder.Decode(&records); err != nil {
return nil, err
}
return records, nil
}