mirror of
https://github.com/lovelaze/nebula-sync.git
synced 2025-11-05 18:29:19 +01:00
Cut instead of split when separating pihole url and password
This commit is contained in:
@@ -7,14 +7,15 @@ import (
|
||||
)
|
||||
|
||||
func TestInit_info(t *testing.T) {
|
||||
|
||||
t.Setenv("NS_DEBUG", "false")
|
||||
Init()
|
||||
|
||||
assert.Equal(t, zerolog.InfoLevel, zerolog.GlobalLevel())
|
||||
}
|
||||
|
||||
func TestInit_debug(t *testing.T) {
|
||||
|
||||
t.Setenv("NS_DEBUG", "true")
|
||||
Init()
|
||||
|
||||
assert.Equal(t, zerolog.DebugLevel, zerolog.GlobalLevel())
|
||||
}
|
||||
|
||||
@@ -25,20 +25,21 @@ func NewPiHole(host, password string) PiHole {
|
||||
}
|
||||
|
||||
func (piHole *PiHole) Decode(value string) error {
|
||||
split := strings.Split(value, "|")
|
||||
if len(split) != 2 {
|
||||
uri, password, found := strings.Cut(value, "|")
|
||||
|
||||
if !found {
|
||||
return fmt.Errorf("invalid pihole format")
|
||||
}
|
||||
|
||||
res, err := url.Parse(split[0])
|
||||
parsedUrl, err := url.Parse(uri)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse url: %s", err)
|
||||
}
|
||||
|
||||
*piHole = PiHole{
|
||||
Url: res,
|
||||
Password: split[1],
|
||||
Url: parsedUrl,
|
||||
Password: password,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/url"
|
||||
"testing"
|
||||
@@ -8,14 +9,16 @@ import (
|
||||
|
||||
func TestPiHole_Decode(t *testing.T) {
|
||||
ph := PiHole{}
|
||||
const uri = "http://localhost:1337"
|
||||
const pw = "asdfa|sdf"
|
||||
|
||||
err := ph.Decode("http://localhost:1337|asdfasdf")
|
||||
err := ph.Decode(fmt.Sprintf("%s|%s", uri, pw))
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedUrl, err := url.Parse("http://localhost:1337")
|
||||
expectedUrl, err := url.Parse(uri)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, expectedUrl, ph.Url)
|
||||
assert.Equal(t, "asdfasdf", ph.Password)
|
||||
assert.Equal(t, pw, ph.Password)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import "github.com/lovelaze/nebula-sync/cmd"
|
||||
import (
|
||||
"github.com/lovelaze/nebula-sync/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
package version
|
||||
|
||||
const Version = "0.1.0"
|
||||
const Version = "0.1.1"
|
||||
|
||||
Reference in New Issue
Block a user