-
Notifications
You must be signed in to change notification settings - Fork 123
/
load_test.go
39 lines (32 loc) · 959 Bytes
/
load_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
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestLoad(t *testing.T) {
const content = "just text"
t.Run("normal msg", func(t *testing.T) {
msg, err := loadMsg(content)
require.NoError(t, err)
require.Equal(t, content, msg)
})
t.Run("file", func(t *testing.T) {
path := filepath.Join(t.TempDir(), "foo.txt")
require.NoError(t, os.WriteFile(path, []byte(content), 0o644))
msg, err := loadMsg("file://" + path)
require.NoError(t, err)
require.Equal(t, content, msg)
})
t.Run("http url", func(t *testing.T) {
msg, err := loadMsg("http://raw.githubusercontent.com/charmbracelet/mods/main/LICENSE")
require.NoError(t, err)
require.Contains(t, msg, "MIT License")
})
t.Run("https url", func(t *testing.T) {
msg, err := loadMsg("https://raw.githubusercontent.com/charmbracelet/mods/main/LICENSE")
require.NoError(t, err)
require.Contains(t, msg, "MIT License")
})
}