mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
test: use white-box testing
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package config_test
|
||||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/crazy-max/diun/v4/internal/config"
|
||||
"github.com/crazy-max/diun/v4/internal/model"
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||
@@ -18,7 +17,7 @@ func TestLoadFile(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
cfg string
|
||||
wantData *config.Config
|
||||
wantData *Config
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
@@ -44,7 +43,7 @@ func TestLoadFile(t *testing.T) {
|
||||
{
|
||||
name: "Success",
|
||||
cfg: "./fixtures/config.test.yml",
|
||||
wantData: &config.Config{
|
||||
wantData: &Config{
|
||||
Db: &model.Db{
|
||||
Path: "diun.db",
|
||||
},
|
||||
@@ -236,7 +235,7 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
|
||||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg, err := config.Load(tt.cfg)
|
||||
cfg, err := Load(tt.cfg)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
@@ -269,7 +268,7 @@ func TestLoadEnv(t *testing.T) {
|
||||
environ: []string{
|
||||
"DIUN_PROVIDERS_DOCKER=true",
|
||||
},
|
||||
expected: &config.Config{
|
||||
expected: &Config{
|
||||
Db: (&model.Db{}).GetDefaults(),
|
||||
Watch: (&model.Watch{}).GetDefaults(),
|
||||
Notif: nil,
|
||||
@@ -294,7 +293,7 @@ func TestLoadEnv(t *testing.T) {
|
||||
"DIUN_REGOPTS_0_TIMEOUT=30s",
|
||||
"DIUN_PROVIDERS_DOCKER=true",
|
||||
},
|
||||
expected: &config.Config{
|
||||
expected: &Config{
|
||||
Db: (&model.Db{}).GetDefaults(),
|
||||
Watch: (&model.Watch{}).GetDefaults(),
|
||||
RegOpts: model.RegOpts{
|
||||
@@ -324,7 +323,7 @@ func TestLoadEnv(t *testing.T) {
|
||||
"DIUN_NOTIF_TELEGRAM_CHATIDS=8547439,1234567",
|
||||
"DIUN_PROVIDERS_SWARM=true",
|
||||
},
|
||||
expected: &config.Config{
|
||||
expected: &Config{
|
||||
Db: (&model.Db{}).GetDefaults(),
|
||||
Watch: (&model.Watch{}).GetDefaults(),
|
||||
Notif: &model.Notif{
|
||||
@@ -350,7 +349,7 @@ func TestLoadEnv(t *testing.T) {
|
||||
"DIUN_NOTIF_SCRIPT_ARGS=-a",
|
||||
"DIUN_PROVIDERS_FILE_DIRECTORY=./fixtures",
|
||||
},
|
||||
expected: &config.Config{
|
||||
expected: &Config{
|
||||
Db: (&model.Db{}).GetDefaults(),
|
||||
Watch: (&model.Watch{}).GetDefaults(),
|
||||
Notif: &model.Notif{
|
||||
@@ -381,7 +380,7 @@ func TestLoadEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
cfg, err := config.Load(tt.cfg)
|
||||
cfg, err := Load(tt.cfg)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
@@ -422,7 +421,7 @@ func TestLoadMixed(t *testing.T) {
|
||||
"DIUN_NOTIF_MAIL_TO=webmaster@foo.com",
|
||||
"DIUN_NOTIF_MAIL_LOCALNAME=foo.com",
|
||||
},
|
||||
expected: &config.Config{
|
||||
expected: &Config{
|
||||
Db: (&model.Db{}).GetDefaults(),
|
||||
Watch: (&model.Watch{}).GetDefaults(),
|
||||
Notif: &model.Notif{
|
||||
@@ -467,7 +466,7 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
|
||||
"DIUN_NOTIF_WEBHOOK_METHOD=GET",
|
||||
"DIUN_NOTIF_WEBHOOK_TIMEOUT=1m",
|
||||
},
|
||||
expected: &config.Config{
|
||||
expected: &Config{
|
||||
Db: (&model.Db{}).GetDefaults(),
|
||||
Watch: (&model.Watch{}).GetDefaults(),
|
||||
Notif: &model.Notif{
|
||||
@@ -502,7 +501,7 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
|
||||
}
|
||||
}
|
||||
|
||||
cfg, err := config.Load(tt.cfg)
|
||||
cfg, err := Load(tt.cfg)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
@@ -526,7 +525,7 @@ func TestValidation(t *testing.T) {
|
||||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg, err := config.Load(tt.cfg)
|
||||
cfg, err := Load(tt.cfg)
|
||||
require.NoError(t, err)
|
||||
_, err = env.Encode("DIUN_", cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package provider_test
|
||||
package provider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/internal/model"
|
||||
"github.com/crazy-max/diun/v4/internal/provider"
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -79,7 +78,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
// Test diun.regopt
|
||||
{
|
||||
@@ -165,7 +164,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Override default image values with labels (true > false)",
|
||||
@@ -226,7 +225,7 @@ func TestValidateImage(t *testing.T) {
|
||||
Name: "myimg",
|
||||
NotifyOn: []model.NotifyOn{},
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Set empty notify_on",
|
||||
@@ -297,7 +296,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Set empty sort_tags",
|
||||
@@ -368,7 +367,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Set empty max_tags",
|
||||
@@ -381,7 +380,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Default max_tags",
|
||||
@@ -679,7 +678,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Set empty platform",
|
||||
@@ -693,7 +692,7 @@ func TestValidateImage(t *testing.T) {
|
||||
Name: "myimg",
|
||||
Platform: model.ImagePlatform{},
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Default platform",
|
||||
@@ -769,7 +768,7 @@ func TestValidateImage(t *testing.T) {
|
||||
expectedImage: model.Image{
|
||||
Name: "myimg",
|
||||
},
|
||||
expectedErr: provider.ErrInvalidLabel,
|
||||
expectedErr: ErrInvalidLabel,
|
||||
},
|
||||
{
|
||||
name: "Set empty metadata key",
|
||||
@@ -860,7 +859,7 @@ func TestValidateImage(t *testing.T) {
|
||||
c := c
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
actualImg, actualErr := provider.ValidateImage(
|
||||
actualImg, actualErr := ValidateImage(
|
||||
c.image,
|
||||
c.metadata,
|
||||
c.labels,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package file_test
|
||||
package file
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/internal/model"
|
||||
"github.com/crazy-max/diun/v4/internal/provider/file"
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/crazy-max/diun/v4/pkg/utl"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -156,7 +155,7 @@ var (
|
||||
)
|
||||
|
||||
func TestListJobFilename(t *testing.T) {
|
||||
fc := file.New(&model.PrdFile{
|
||||
fc := New(&model.PrdFile{
|
||||
Filename: "./fixtures/dockerhub.yml",
|
||||
}, &defaultImageDefaults)
|
||||
|
||||
@@ -164,7 +163,7 @@ func TestListJobFilename(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListJobDirectory(t *testing.T) {
|
||||
fc := file.New(&model.PrdFile{
|
||||
fc := New(&model.PrdFile{
|
||||
Directory: "./fixtures",
|
||||
}, &defaultImageDefaults)
|
||||
|
||||
@@ -172,7 +171,7 @@ func TestListJobDirectory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDefaultImageOptions(t *testing.T) {
|
||||
fc := file.New(&model.PrdFile{
|
||||
fc := New(&model.PrdFile{
|
||||
Filename: "./fixtures/dockerhub.yml",
|
||||
}, &model.Image{WatchRepo: utl.NewTrue()})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user