forked from mattn/gom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgomfile_test.go
111 lines (102 loc) · 2.48 KB
/
gomfile_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"io/ioutil"
"reflect"
"testing"
)
func tempGomfile(content string) (string, error) {
f, err := ioutil.TempFile("", "gom")
if err != nil {
return "", err
}
defer f.Close()
_, err = f.WriteString(content)
if err != nil {
return "", err
}
name := f.Name()
return name, nil
}
func TestGomfile1(t *testing.T) {
filename, err := tempGomfile(`
gom 'github.com/mattn/go-sqlite3', :tag => '>3.33'
`)
if err != nil {
t.Fatal(err)
}
goms, err := parseGomfile(filename)
if err != nil {
t.Fatal(err)
}
expected := []Gom{
{name: "github.com/mattn/go-sqlite3", options: map[string]interface{}{"tag": ">3.33"}},
}
if !reflect.DeepEqual(goms, expected) {
t.Fatalf("Expected %v, but %v:", expected, goms)
}
}
func TestGomfile2(t *testing.T) {
filename, err := tempGomfile(`
gom 'github.com/mattn/go-sqlite3', :tag => '>3.33'
gom 'github.com/mattn/go-gtk'
`)
if err != nil {
t.Fatal(err)
}
goms, err := parseGomfile(filename)
if err != nil {
t.Fatal(err)
}
expected := []Gom{
{name: "github.com/mattn/go-sqlite3", options: map[string]interface{}{"tag": ">3.33"}},
{name: "github.com/mattn/go-gtk", options: map[string]interface{}{}},
}
if !reflect.DeepEqual(goms, expected) {
t.Fatalf("Expected %v, but %v:", expected, goms)
}
}
func TestGomfile3(t *testing.T) {
filename, err := tempGomfile(`
gom 'github.com/mattn/go-sqlite3', :tag => '3.14', :commit => 'asdfasdf'
gom 'github.com/mattn/go-gtk', :foobar => 'barbaz'
`)
if err != nil {
t.Fatal(err)
}
goms, err := parseGomfile(filename)
if err != nil {
t.Fatal(err)
}
expected := []Gom{
{name: "github.com/mattn/go-sqlite3", options: map[string]interface{}{"tag": "3.14", "commit": "asdfasdf"}},
{name: "github.com/mattn/go-gtk", options: map[string]interface{}{"foobar": "barbaz"}},
}
if !reflect.DeepEqual(goms, expected) {
t.Fatalf("Expected %v, but %v:", expected, goms)
}
}
func TestGomfile4(t *testing.T) {
filename, err := tempGomfile(`
group :development do
gom 'github.com/mattn/go-sqlite3', :tag => '3.14', :commit => 'asdfasdf'
end
group :test do
gom 'github.com/mattn/go-gtk', :foobar => 'barbaz'
end
`)
if err != nil {
t.Fatal(err)
}
*developmentEnv = true
goms, err := parseGomfile(filename)
*developmentEnv = false
if err != nil {
t.Fatal(err)
}
expected := []Gom{
{name: "github.com/mattn/go-sqlite3", options: map[string]interface{}{"tag": "3.14", "commit": "asdfasdf"}},
}
if !reflect.DeepEqual(goms, expected) {
t.Fatalf("Expected %v, but %v:", expected, goms)
}
}