30 lines
		
	
	
	
		
			679 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			679 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package config
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| func TestLoadTomlMissing(t *testing.T) {
 | |
| 	_, e := LoadFromToml("not-a-real-filee")
 | |
| 	assert.Error(t, e)
 | |
| }
 | |
| 
 | |
| func TestLoadTomlGood(t *testing.T) {
 | |
| 	tmp, _ := os.CreateTemp("", "*.toml")
 | |
| 	defer os.Remove(tmp.Name())
 | |
| 	defer tmp.Close()
 | |
| 	fmt.Fprintln(tmp, `name = "Cool"`)
 | |
| 	fmt.Fprintln(tmp, "[conn]")
 | |
| 	fmt.Fprintln(tmp, `store = "sqlite"`)
 | |
| 	fmt.Fprintln(tmp, "[conn.settings]")
 | |
| 	fmt.Fprintln(tmp, `num = 42`)
 | |
| 	c, e := LoadFromToml(tmp.Name())
 | |
| 	assert.NoError(t, e)
 | |
| 	assert.Equal(t, "Cool", c.Name)
 | |
| 	assert.Equal(t, "sqlite", c.Conn.Store)
 | |
| 	assert.Equal(t, int64(42), c.Conn.Settings["num"])
 | |
| }
 |