mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2025-06-27 05:40:28 +01:00
remove config/util
This commit is contained in:
parent
2035e158b1
commit
8ab543df0f
@ -1,43 +0,0 @@
|
||||
// Package main provides the configuration loading functionality for the vbantxt application.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Connection connection `toml:"connection"`
|
||||
}
|
||||
|
||||
func (c config) String() string {
|
||||
return fmt.Sprintf(
|
||||
"host: %s port: %d streamname: %s",
|
||||
c.Connection.Host, c.Connection.Port, c.Connection.Streamname)
|
||||
}
|
||||
|
||||
type connection struct {
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
Streamname string `toml:"streamname"`
|
||||
}
|
||||
|
||||
func loadConfig(configPath string) (*connection, error) {
|
||||
_, err := os.Stat(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config config
|
||||
|
||||
_, err = toml.DecodeFile(configPath, &config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(config)
|
||||
|
||||
return &config.Connection, nil
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLoadConfig_Success(t *testing.T) {
|
||||
conn, err := loadConfig("testdata/config.toml")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, conn.Host, "localhost")
|
||||
assert.Equal(t, conn.Port, 7000)
|
||||
assert.Equal(t, conn.Streamname, "vbantxt")
|
||||
}
|
||||
|
||||
func TestLoadConfig_Errors(t *testing.T) {
|
||||
tt := map[string]struct {
|
||||
input string
|
||||
err string
|
||||
}{
|
||||
"no such file": {
|
||||
input: "/no/such/dir/config.toml",
|
||||
err: "no such file or directory",
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tt {
|
||||
_, err := loadConfig("/no/such/dir/config.toml")
|
||||
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
assert.ErrorContains(t, err, tc.err)
|
||||
})
|
||||
}
|
||||
}
|
4
cmd/vbantxt/testdata/config.toml
vendored
4
cmd/vbantxt/testdata/config.toml
vendored
@ -1,4 +0,0 @@
|
||||
[connection]
|
||||
host = "localhost"
|
||||
port = 7000
|
||||
streamname = "vbantxt"
|
@ -1,17 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"slices"
|
||||
)
|
||||
|
||||
func flagsPassed(flags []string) bool {
|
||||
found := false
|
||||
flag.Visit(func(f *flag.Flag) {
|
||||
if slices.Contains(flags, f.Name) {
|
||||
found = true
|
||||
return
|
||||
}
|
||||
})
|
||||
return found
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user