This repository has been archived by the owner on Jul 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
nut_test.go
77 lines (65 loc) · 2.06 KB
/
nut_test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package nut_test
import (
"fmt"
"os"
"path/filepath"
"runtime"
. "."
. "launchpad.net/gocheck"
)
type N struct {
nf *NutFile
}
var _ = Suite(&N{})
func (f *N) SetUpTest(c *C) {
file, err := os.Open("../test_nut1/test_nut1-0.0.1.nut")
c.Assert(err, IsNil)
defer file.Close()
fi, err := file.Stat()
c.Assert(err, IsNil)
nf := new(NutFile)
n, err := nf.ReadFrom(file)
c.Assert(err, IsNil)
c.Assert(n, Equals, fi.Size())
f.nf = nf
}
func (f *N) TestNutFileReadFrom(c *C) {
c.Check(f.nf.Spec.Version.String(), Equals, "0.0.1")
c.Check(f.nf.Version.String(), Equals, "0.0.1")
c.Check(f.nf.Vendor, Equals, "debug")
c.Check(f.nf.Package.Name, Equals, "test_nut1")
c.Check(f.nf.Name, Equals, "test_nut1")
c.Check(f.nf.FileName(), Equals, "test_nut1-0.0.1.nut")
c.Check(f.nf.FilePath("prefix"), Equals, filepath.FromSlash("prefix/debug/test_nut1-0.0.1.nut"))
c.Check(f.nf.ImportPath("prefix"), Equals, "prefix/debug/test_nut1")
c.Check(f.nf.Prefix("prefix/debug/test_nut1"), Equals, "prefix")
c.Check(f.nf.Doc, Equals, "Package test_nut1 is used to test nut.")
c.Check(f.nf.GoFiles, DeepEquals, []string{"test_nut1.go", fmt.Sprintf("test_nut1_%s.go", runtime.GOOS)})
c.Check(len(f.nf.Reader.File), Equals, 11)
names := make([]string, 0, 11)
for _, f := range f.nf.Reader.File {
names = append(names, f.Name)
}
c.Check([]string{"test_nut1.go", "test_nut1_darwin.go", "test_nut1_freebsd.go", "test_nut1_linux.go", "test_nut1_netbsd.go",
"test_nut1_openbsd.go", "test_nut1_plan9.go", "test_nut1_windows.go", "README", "LICENSE", "nut.json"},
DeepEquals, names)
}
func (f *N) TestNutFileReadFile(c *C) {
nf := new(NutFile)
err := nf.ReadFile("../test_nut1/test_nut1-0.0.1.nut")
c.Check(err, IsNil)
c.Check(nf, DeepEquals, f.nf)
}
func (f *N) TestNutReadFrom(c *C) {
pwd, err := os.Getwd()
c.Assert(err, IsNil)
c.Assert(os.Chdir("../test_nut1"), IsNil)
defer func() {
c.Assert(os.Chdir(pwd), IsNil)
}()
nut := new(Nut)
err = nut.ReadFrom(".")
c.Check(err, IsNil)
c.Check(nut.Spec, DeepEquals, f.nf.Spec)
c.Check(nut.Package, DeepEquals, f.nf.Package)
}