eb61d9672367b92e412a1c2be54f69b1a9aee342
[lightning.git] / pipeline_test.go
1 package main
2
3 import (
4         "bytes"
5         "fmt"
6         "io"
7         "os"
8         "sync"
9
10         "gopkg.in/check.v1"
11 )
12
13 type pipelineSuite struct{}
14
15 var _ = check.Suite(&pipelineSuite{})
16
17 func (s *pipelineSuite) TestImport(c *check.C) {
18         for _, infile := range []string{
19                 "testdata/pipeline1/",
20                 "testdata/ref.fasta",
21         } {
22                 c.Logf("TestImport: %s", infile)
23                 var wg sync.WaitGroup
24
25                 statsin, importout := io.Pipe()
26                 wg.Add(1)
27                 go func() {
28                         defer wg.Done()
29                         code := (&importer{}).RunCommand("lightning import", []string{"-local=true", "-skip-ooo=true", "-output-tiles", "-tag-library", "testdata/tags", infile}, bytes.NewReader(nil), importout, os.Stderr)
30                         c.Check(code, check.Equals, 0)
31                         importout.Close()
32                 }()
33                 statsout := &bytes.Buffer{}
34                 wg.Add(1)
35                 go func() {
36                         defer wg.Done()
37                         code := (&stats{}).RunCommand("lightning stats", []string{"-local"}, statsin, statsout, os.Stderr)
38                         c.Check(code, check.Equals, 0)
39                 }()
40                 wg.Wait()
41                 c.Logf("%s", statsout.String())
42         }
43 }
44
45 func (s *pipelineSuite) TestImportMerge(c *check.C) {
46         libfile := make([]string, 2)
47         tmpdir := c.MkDir()
48
49         var wg sync.WaitGroup
50         for i, infile := range []string{
51                 "testdata/pipeline1/",
52                 "testdata/ref.fasta",
53         } {
54                 i, infile := i, infile
55                 c.Logf("TestImportMerge: %s", infile)
56                 libfile[i] = fmt.Sprintf("%s/%d.gob", tmpdir, i)
57                 wg.Add(1)
58                 go func() {
59                         defer wg.Done()
60                         code := (&importer{}).RunCommand("lightning import", []string{"-local=true", "-o=" + libfile[i], "-skip-ooo=true", "-output-tiles", "-tag-library", "testdata/tags", infile}, bytes.NewReader(nil), &bytes.Buffer{}, os.Stderr)
61                         c.Check(code, check.Equals, 0)
62                 }()
63         }
64         wg.Wait()
65
66         merged := &bytes.Buffer{}
67         code := (&merger{}).RunCommand("lightning merge", []string{"-local", libfile[0], libfile[1]}, bytes.NewReader(nil), merged, os.Stderr)
68         c.Check(code, check.Equals, 0)
69         c.Logf("len(merged) %d", merged.Len())
70
71         statsout := &bytes.Buffer{}
72         code = (&stats{}).RunCommand("lightning stats", []string{"-local"}, merged, statsout, os.Stderr)
73         c.Check(code, check.Equals, 0)
74         c.Check(statsout.Len() > 0, check.Equals, true)
75         c.Logf("%s", statsout.String())
76 }