forked from tidbyt/pixlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest_test.go
140 lines (118 loc) · 3.07 KB
/
manifest_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
130
131
132
133
134
135
136
137
138
139
140
package manifest_test
import (
"bytes"
_ "embed"
"io"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"tidbyt.dev/pixlet/manifest"
)
//go:embed testdata/source.star
var source []byte
var output string = `---
id: foo-tracker
name: Foo Tracker
summary: Track realtime foo
desc: The foo tracker provides realtime feeds for foo.
author: Tidbyt
fileName: foo_tracker.star
packageName: footracker
`
func TestManifest(t *testing.T) {
m := manifest.Manifest{
ID: "foo-tracker",
Name: "Foo Tracker",
Summary: "Track realtime foo",
Desc: "The foo tracker provides realtime feeds for foo.",
Author: "Tidbyt",
FileName: "foo_tracker.star",
PackageName: "footracker",
Source: source,
}
expected, err := os.ReadFile("testdata/source.star")
assert.NoError(t, err)
assert.Equal(t, m.Source, expected)
}
func TestLoadManifest(t *testing.T) {
p := filepath.Join("testdata", "manifest.yaml")
f, err := os.Open(p)
assert.NoError(t, err)
defer f.Close()
m, err := manifest.LoadManifest(f)
assert.NoError(t, err)
assert.Equal(t, m.ID, "fuzzy-clock")
assert.Equal(t, m.Name, "Fuzzy Clock")
assert.Equal(t, m.Author, "Max Timkovich")
assert.Equal(t, m.Summary, "Human readable time")
assert.Equal(t, m.Desc, "Display the time in a groovy, human-readable way.")
assert.Equal(t, m.FileName, "fuzzy_clock.star")
assert.Equal(t, m.PackageName, "fuzzyclock")
}
func TestWriteManifest(t *testing.T) {
m := manifest.Manifest{
ID: "foo-tracker",
Name: "Foo Tracker",
Summary: "Track realtime foo",
Desc: "The foo tracker provides realtime feeds for foo.",
Author: "Tidbyt",
FileName: "foo_tracker.star",
PackageName: "footracker",
Source: source,
}
buff := bytes.Buffer{}
err := m.WriteManifest(&buff)
assert.NoError(t, err)
b, err := io.ReadAll(&buff)
assert.NoError(t, err)
assert.Equal(t, output, string(b))
}
func TestGeneratePackageName(t *testing.T) {
type test struct {
input string
want string
}
tests := []test{
{input: "Cool App", want: "coolapp"},
{input: "CoolApp", want: "coolapp"},
{input: "cool-app", want: "coolapp"},
{input: "cool_app", want: "coolapp"},
}
for _, tc := range tests {
got := manifest.GeneratePackageName(tc.input)
assert.Equal(t, tc.want, got)
}
}
func TestGenerateFileName(t *testing.T) {
type test struct {
input string
want string
}
tests := []test{
{input: "Cool App", want: "cool_app.star"},
{input: "CoolApp", want: "coolapp.star"},
{input: "cool-app", want: "cool_app.star"},
{input: "cool_app", want: "cool_app.star"},
}
for _, tc := range tests {
got := manifest.GenerateFileName(tc.input)
assert.Equal(t, tc.want, got)
}
}
func TestGenerateID(t *testing.T) {
type test struct {
input string
want string
}
tests := []test{
{input: "Cool App", want: "cool-app"},
{input: "CoolApp", want: "coolapp"},
{input: "cool-app", want: "cool-app"},
{input: "cool_app", want: "cool-app"},
}
for _, tc := range tests {
got := manifest.GenerateID(tc.input)
assert.Equal(t, tc.want, got)
}
}