File: nt_test.go

package info (click to toggle)
golang-github-knadh-koanf 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 808 kB
  • sloc: sh: 31; makefile: 14
file content (38 lines) | stat: -rw-r--r-- 808 bytes parent folder | download
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
package nestedtext_test

import (
	"testing"

	"github.com/knadh/koanf/parsers/nestedtext"
)

func TestParser(t *testing.T) {
	// test input in NestedText format
	ntsource := `ports:
  - 6483
  - 8020
  - 9332
timeout: 20
`
	// Test decoder
	nt := nestedtext.Parser()
	c, err := nt.Unmarshal([]byte(ntsource))
	if err != nil {
		t.Fatal("Unmarshal of NestedText input failed")
	}
	timeout := c["timeout"]
	if timeout != "20" {
		t.Logf("config-tree: %#v", c)
		t.Errorf("expected timeout-parameter to be 20, is %q", timeout)
	}

	// test encoder
	out, err := nt.Marshal(c)
	if err != nil {
		t.Fatal("Marshal of config to NestedText failed")
	}
	if string(out) != ntsource {
		t.Logf("config-text: %q", string(out))
		t.Errorf("expected output of Marshal(…) to equal input to Unmarshal(…); didn't")
	}
}