Skip to content

Commit

Permalink
Add test for config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielunderwood committed Sep 18, 2023
1 parent 6c30aaa commit 00649fa
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
61 changes: 61 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"fmt"
"reflect"
"testing"
)

func TestLoadConfig(t *testing.T) {
cases := map[string]Config{
"empty.yaml": {},
"all-providers.yaml": {
Feeds: []Feed{"example.com/feed.xml"},
Outputs: []Output{
{
Kind: "s3",
Config: map[string]string{
"endpoint": "https://s3.example.com",
"region": "test-region",
"accesskeyid": "test-key",
"accesssecret": "test-secret",
"bucket": "test-bucket",
"keyformat": "{{ .PublishedParsed.UTC.Year }}/{{ .PublishedParsed.UTC.Month }}/{{ .PublishedParsed.UTC.Day }}",
},
},
{
Kind: "file",
Config: map[string]string{
"pathformat": "./data/{{ .PublishedParsed.UTC.Year }}/{{ .PublishedParsed.UTC.Month }}/{{ .PublishedParsed.UTC.Day }}",
},
},
{
Kind: "kafka",
Config: map[string]string{
"broker": "127.0.0.1:9092",
"topic": "feeds",
},
},
{
Kind: "discord",
Config: map[string]string{
"url": "https://discord.example.com/webhook",
},
},
},
Redis: RedisConfig{
Host: "127.0.0.1:6379",
},
},
}
for file, expected := range cases {
t.Run(file, func(t *testing.T) {
t.Parallel()
filename := fmt.Sprintf("testdata/%s", file)
config := loadConfig(filename)
if !reflect.DeepEqual(config, expected) {
t.Errorf("Configs do not match:\n%s\n%s", config, expected)
}
})
}
}
23 changes: 23 additions & 0 deletions testdata/all-providers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
outputs:
- kind: s3
config:
endpoint: https://s3.example.com
region: test-region
accesskeyid: test-key
accesssecret: test-secret
bucket: test-bucket
keyformat: "{{ .PublishedParsed.UTC.Year }}/{{ .PublishedParsed.UTC.Month }}/{{ .PublishedParsed.UTC.Day }}"
- kind: file
config:
pathformat: "./data/{{ .PublishedParsed.UTC.Year }}/{{ .PublishedParsed.UTC.Month }}/{{ .PublishedParsed.UTC.Day }}"
- kind: kafka
config:
broker: "127.0.0.1:9092"
topic: feeds
- kind: discord
config:
url: "https://discord.example.com/webhook"
redis:
host: 127.0.0.1:6379
feeds:
- example.com/feed.xml
Empty file added testdata/empty.yaml
Empty file.

0 comments on commit 00649fa

Please sign in to comment.