aboutsummaryrefslogtreecommitdiffsponsor
path: root/internal/service/service_json_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/service/service_json_test.go')
-rw-r--r--internal/service/service_json_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/service/service_json_test.go b/internal/service/service_json_test.go
new file mode 100644
index 0000000..c8e073a
--- /dev/null
+++ b/internal/service/service_json_test.go
@@ -0,0 +1,37 @@
+package service
+
+import (
+ "encoding/json"
+ "testing"
+
+ "git.server.ky/slackcoder/mirror/internal"
+ "github.com/stretchr/testify/require"
+)
+
+func mustJSON(arg interface{}) string {
+ buf, err := json.Marshal(arg)
+ if err != nil {
+ panic(err)
+ }
+
+ return string(buf)
+}
+
+func TestMirrorUnmarshalJSON(t *testing.T) {
+ str := mustJSON(map[string]interface{}{
+ "method": "git",
+ "from": "https://git.taler.net/merchant.git",
+ "to": "/mirror/merchant",
+ })
+
+ exp := Mirror{
+ Method: "git",
+ From: internal.MustURL("https://git.taler.net/merchant.git"),
+ To: internal.MustURL("/mirror/merchant"),
+ }
+
+ var s Mirror
+ err := json.Unmarshal([]byte(str), &s)
+ require.NoError(t, err)
+ require.Equal(t, exp.String(), s.String())
+}