test new config parsing
This commit is contained in:
parent
4edc625331
commit
bc5060b218
1 changed files with 23 additions and 5 deletions
|
@ -2,17 +2,19 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"heckel.io/ntfy/client"
|
|
||||||
"heckel.io/ntfy/test"
|
|
||||||
"heckel.io/ntfy/util"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"heckel.io/ntfy/client"
|
||||||
|
"heckel.io/ntfy/test"
|
||||||
|
"heckel.io/ntfy/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -70,6 +72,22 @@ func TestCLI_Serve_WebSocket(t *testing.T) {
|
||||||
require.Equal(t, "mytopic", m.Topic)
|
require.Equal(t, "mytopic", m.Topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIP_Host_Parsing(t *testing.T) {
|
||||||
|
cases := map[string]string{
|
||||||
|
"1.1.1.1": "1.1.1.1/32",
|
||||||
|
"fd00::1234": "fd00::1234/128",
|
||||||
|
"192.168.0.3/24": "192.168.0.0/24",
|
||||||
|
"10.1.2.3/8": "10.0.0.0/8",
|
||||||
|
"201:be93::4a6/21": "201:b800::/21",
|
||||||
|
}
|
||||||
|
for q, expectedAnswer := range cases {
|
||||||
|
ips, err := parseIPHostPrefix(q)
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.Equal(t, 1, len(ips))
|
||||||
|
assert.Equal(t, expectedAnswer, ips[0].String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func newEmptyFile(t *testing.T) string {
|
func newEmptyFile(t *testing.T) string {
|
||||||
filename := filepath.Join(t.TempDir(), "empty")
|
filename := filepath.Join(t.TempDir(), "empty")
|
||||||
require.Nil(t, os.WriteFile(filename, []byte{}, 0600))
|
require.Nil(t, os.WriteFile(filename, []byte{}, 0600))
|
||||||
|
|
Loading…
Reference in a new issue