shoebill/internal/config/config_test.go

54 lines
1.1 KiB
Go
Raw Normal View History

2023-07-20 09:26:25 +00:00
package config_test
import (
"os"
"testing"
2023-08-02 15:00:34 +00:00
"git.badhouseplants.net/allanger/shoebill/internal/config"
"git.badhouseplants.net/allanger/shoebill/internal/config/repository"
2023-07-20 09:26:25 +00:00
"github.com/stretchr/testify/assert"
)
func helperCreateFile(t *testing.T) *os.File {
f, err := os.CreateTemp("", "sample")
if err != nil {
t.Error(err)
}
t.Logf("file is created: %s", f.Name())
return f
}
func helperFillFile(t *testing.T, f *os.File, content string) {
_, err := f.WriteString(content)
if err != nil {
t.Error(err)
}
}
func TestNewConfigFromFile(t *testing.T) {
f := helperCreateFile(t)
defer os.Remove(f.Name())
const configExample = `---
repositories:
- name: test
url: https://test.de
`
helperFillFile(t, f, configExample)
configGot, err := config.NewConfigFromFile(f.Name())
if err != nil {
t.Error(err)
}
repositoryWant := &repository.Repository{
Name: "test",
URL: "https://test.de",
}
configWant := &config.Config{
Repositories: repository.Repositories{repositoryWant},
}
assert.Equal(t, configWant.Repositories, configGot.Repositories)
}