-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser_test.go
129 lines (111 loc) · 3.3 KB
/
parser_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package metadata_test
import (
"fmt"
"strings"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/go-chef/metadata-parser"
"github.com/hashicorp/go-version"
)
// Ensure the parser can parse strings into Statement ASTs.
func TestParser_ParseStatement(t *testing.T) {
var test_metadata = `
name "awesomesauce"
description 'some description'
long_description File.Read('README.md')
version "1.0.1"
depends 'yum', '> 3.0.0'
depends 'mysql', "3.0.0"
depends 'redis'
depends 'thing'
depends 'thisthing'
depends 'packagecloud'
`
c, _ := version.NewConstraint("> 3.0.0")
yumDep := metadata.Dependency{
Name: "yum",
Constraint: c,
}
c, _ = version.NewConstraint("3.0.0")
mysqlDep := metadata.Dependency{
Name: "mysql",
Constraint: c,
}
redisDep := metadata.Dependency{
Name: "redis",
Constraint: version.Constraints{},
}
v, err := version.NewVersion("1.0.1")
expect := metadata.Metadata{
Depends: []metadata.Dependency{yumDep, mysqlDep, redisDep},
Name: "awesomesauce",
Version: *v,
}
meta, err := metadata.NewParser(strings.NewReader(test_metadata)).Parse()
if err != nil {
fmt.Println(" Error parsing: ", err)
t.Fail()
}
// if !reflect.DeepEqual(meta, expect) {
if meta.Name != expect.Name {
fmt.Printf("Name Mismatch, expected '%s' got '%s'", expect.Name, meta.Name)
t.Fail()
}
if meta.Version.String() != expect.Version.String() {
fmt.Printf("Name Mismatch, expected '%s' got '%s'", expect.Version, meta.Version)
t.Fail()
}
for i, _ := range []string{"yum", "mysql", "redis"} {
if meta.Depends[i].Name != expect.Depends[i].Name {
fmt.Printf("Dep Mismatch,\nexpected: %s\n got: %s", spew.Sdump(expect.Depends[i]), spew.Sdump(meta.Depends[i]))
t.Fail()
}
if meta.Depends[i].Constraint.String() != expect.Depends[i].Constraint.String() {
fmt.Printf("Dep Mismatch,\nexpected: %s\n got: %s", spew.Sdump(expect.Depends[i]), spew.Sdump(meta.Depends[i]))
t.Fail()
}
}
if len(meta.Depends) != 6 {
t.Fatal("Expected len of deps to == 6, got ", len(meta.Depends))
}
}
func TestParser_CommentMeta(t *testing.T) {
var test_metadata = `
#
# Author:: Jesse Nelson <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name 'user'
version '1.0.24'
maintainer 'Jesse Nelson'
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Create system user'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
depends 'poise', '~> 1.0'
depends 'sudo', '~> 2.5' #stuff
depends 'user', '~> 0.4'
# ohai
depends 'ssh', '~> 0.10.4'
depends 'dnf' #things
`
meta, err := metadata.NewParser(strings.NewReader(test_metadata)).Parse()
if err != nil {
fmt.Println(" Error parsing: ", err)
t.Fail()
}
if len(meta.Depends) != 5 {
t.Fatal("Expected len of deps to == 5, got ", len(meta.Depends))
}
}