mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-26 07:13:48 +01:00
Config test
This commit is contained in:
1
internal/config/config.invalid.yml
Normal file
1
internal/config/config.invalid.yml
Normal file
@@ -0,0 +1 @@
|
||||
invalid testdata file
|
||||
63
internal/config/config.test.yml
Normal file
63
internal/config/config.test.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
db:
|
||||
path: diun.db
|
||||
|
||||
watch:
|
||||
workers: 100
|
||||
schedule: "*/30 * * * * *"
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
notif:
|
||||
mail:
|
||||
enable: false
|
||||
host: localhost
|
||||
port: 25
|
||||
ssl: false
|
||||
insecure_skip_verify: false
|
||||
username:
|
||||
password:
|
||||
from:
|
||||
to:
|
||||
webhook:
|
||||
enable: false
|
||||
endpoint: http://webhook.foo.com/sd54qad89azd5a
|
||||
method: GET
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
Authorization: Token123456
|
||||
timeout: 10
|
||||
|
||||
regopts:
|
||||
someregopts:
|
||||
timeout: 5
|
||||
bintrayoptions:
|
||||
username: foo
|
||||
password: bar
|
||||
|
||||
image:
|
||||
- name: docker.io/crazymax/nextcloud:latest
|
||||
regopts_id: someregopts
|
||||
- name: crazymax/swarm-cronjob
|
||||
watch_repo: true
|
||||
include_tags:
|
||||
- ^1\.2\..*
|
||||
- name: jfrog-docker-reg2.bintray.io/jfrog/artifactory-oss:4.0.0
|
||||
regopts_id: bintrayoptions
|
||||
- name: docker.bintray.io/jfrog/xray-server:2.8.6
|
||||
watch_repo: true
|
||||
max_tags: 50
|
||||
- name: quay.io/coreos/hyperkube
|
||||
- name: docker.io/portainer/portainer
|
||||
watch_repo: true
|
||||
max_tags: 10
|
||||
include_tags:
|
||||
- ^(0|[1-9]\d*)\..*
|
||||
- name: traefik
|
||||
watch_repo: true
|
||||
- name: docker.io/graylog/graylog:3.2.0
|
||||
- name: jacobalberty/unifi:5.9
|
||||
- name: quay.io/coreos/hyperkube:v1.1.7-coreos.1
|
||||
- name: crazymax/ddns-route53
|
||||
watch_repo: true
|
||||
include_tags:
|
||||
- ^1\..*
|
||||
147
internal/config/config_test.go
Normal file
147
internal/config/config_test.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/internal/config"
|
||||
"github.com/crazy-max/diun/internal/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
flags model.Flags
|
||||
wantData *config.Config
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Fail on non-existing file",
|
||||
flags: model.Flags{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Fail on wrong file format",
|
||||
flags: model.Flags{
|
||||
Cfgfile: "config.invalid.yml",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Success",
|
||||
flags: model.Flags{
|
||||
Cfgfile: "config.test.yml",
|
||||
},
|
||||
wantData: &config.Config{
|
||||
Flags: model.Flags{
|
||||
Cfgfile: "config.test.yml",
|
||||
},
|
||||
App: model.App{
|
||||
ID: "diun",
|
||||
Name: "Diun",
|
||||
Desc: "Docker image update notifier",
|
||||
URL: "https://github.com/crazy-max/diun",
|
||||
Author: "CrazyMax",
|
||||
Version: "test",
|
||||
},
|
||||
Db: model.Db{
|
||||
Path: "diun.db",
|
||||
},
|
||||
Watch: model.Watch{
|
||||
Workers: 100,
|
||||
Schedule: "*/30 * * * * *",
|
||||
Os: "linux",
|
||||
Arch: "amd64",
|
||||
},
|
||||
Notif: model.Notif{
|
||||
Mail: model.Mail{
|
||||
Enable: false,
|
||||
Host: "localhost",
|
||||
Port: 25,
|
||||
SSL: false,
|
||||
InsecureSkipVerify: false,
|
||||
},
|
||||
Webhook: model.Webhook{
|
||||
Enable: false,
|
||||
Endpoint: "http://webhook.foo.com/sd54qad89azd5a",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Token123456",
|
||||
},
|
||||
Timeout: 10,
|
||||
},
|
||||
},
|
||||
RegOpts: map[string]model.RegOpts{
|
||||
"someregopts": {
|
||||
Timeout: 5,
|
||||
},
|
||||
"bintrayoptions": {
|
||||
Username: "foo",
|
||||
Password: "bar",
|
||||
},
|
||||
},
|
||||
Image: []model.Image{
|
||||
{
|
||||
Name: "docker.io/crazymax/nextcloud:latest",
|
||||
RegOptsID: "someregopts",
|
||||
},
|
||||
{
|
||||
Name: "crazymax/swarm-cronjob",
|
||||
WatchRepo: true,
|
||||
IncludeTags: []string{
|
||||
`^1\.2\..*`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "jfrog-docker-reg2.bintray.io/jfrog/artifactory-oss:4.0.0",
|
||||
RegOptsID: "bintrayoptions",
|
||||
},
|
||||
{
|
||||
Name: "docker.bintray.io/jfrog/xray-server:2.8.6",
|
||||
WatchRepo: true,
|
||||
MaxTags: 50,
|
||||
},
|
||||
{
|
||||
Name: "quay.io/coreos/hyperkube",
|
||||
},
|
||||
{
|
||||
Name: "docker.io/portainer/portainer",
|
||||
WatchRepo: true,
|
||||
MaxTags: 10,
|
||||
IncludeTags: []string{
|
||||
`^(0|[1-9]\d*)\..*`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "traefik",
|
||||
WatchRepo: true,
|
||||
},
|
||||
{
|
||||
Name: "docker.io/graylog/graylog:3.2.0",
|
||||
},
|
||||
{
|
||||
Name: "jacobalberty/unifi:5.9",
|
||||
},
|
||||
{
|
||||
Name: "quay.io/coreos/hyperkube:v1.1.7-coreos.1",
|
||||
},
|
||||
{
|
||||
Name: "crazymax/ddns-route53",
|
||||
WatchRepo: true,
|
||||
IncludeTags: []string{
|
||||
`^1\..*`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg, err := config.Load(tt.flags, "test")
|
||||
assert.Equal(t, tt.wantData, cfg)
|
||||
assert.Equal(t, tt.wantErr, err != nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user