MCPcopy
hub / github.com/tuna/tunasync / TestConfig

Function TestConfig

manager/config_test.go:14–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestConfig(t *testing.T) {
15 var cfgBlob = `
16 debug = true
17 [server]
18 addr = "0.0.0.0"
19 port = 5000
20
21 [files]
22 status_file = "/tmp/tunasync.json"
23 db_file = "/var/lib/tunasync/tunasync.db"
24 `
25
26 Convey("toml decoding should work", t, func() {
27
28 var conf Config
29 _, err := toml.Decode(cfgBlob, &conf)
30 ShouldEqual(err, nil)
31 ShouldEqual(conf.Server.Addr, "0.0.0.0")
32 ShouldEqual(conf.Server.Port, 5000)
33 ShouldEqual(conf.Files.StatusFile, "/tmp/tunasync.json")
34 ShouldEqual(conf.Files.DBFile, "/var/lib/tunasync/tunasync.db")
35 })
36
37 Convey("load Config should work", t, func() {
38 Convey("create config file & cli context", func() {
39 tmpfile, err := os.CreateTemp("", "tunasync")
40 So(err, ShouldEqual, nil)
41 defer os.Remove(tmpfile.Name())
42
43 err = os.WriteFile(tmpfile.Name(), []byte(cfgBlob), 0644)
44 So(err, ShouldEqual, nil)
45 defer tmpfile.Close()
46
47 app := cli.NewApp()
48 app.Flags = []cli.Flag{
49 &cli.StringFlag{
50 Name: "config",
51 Aliases: []string{"c"},
52 },
53 &cli.StringFlag{
54 Name: "addr",
55 },
56 &cli.IntFlag{
57 Name: "port",
58 },
59 &cli.StringFlag{
60 Name: "cert",
61 },
62 &cli.StringFlag{
63 Name: "key",
64 },
65 &cli.StringFlag{
66 Name: "status-file",
67 },
68 &cli.StringFlag{
69 Name: "db-file",
70 },
71 }

Callers

nothing calls this directly

Calls 6

RemoveMethod · 0.80
LoadConfigFunction · 0.70
NameMethod · 0.65
CloseMethod · 0.65
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected