54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package config_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"git.badhouseplants.net/allanger/shoebill/pkg/config"
|
|
"git.badhouseplants.net/allanger/shoebill/pkg/repository"
|
|
"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)
|
|
}
|