mirror of
https://github.com/crazy-max/diun.git
synced 2025-04-04 19:45:20 +00:00
test: use white-box testing
This commit is contained in:
parent
bc5cdf7aa1
commit
49b8852a04
10 changed files with 103 additions and 113 deletions
internal
pkg
|
@ -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()})
|
||||
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
package dockerfile_test
|
||||
package dockerfile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/dockerfile"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
dc *dockerfile.Client
|
||||
dc *Client
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
|
||||
dc, err = dockerfile.New(dockerfile.Options{
|
||||
dc, err = New(Options{
|
||||
Filename: "./fixtures/valid.Dockerfile",
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -60,7 +59,7 @@ func TestLoadFile(t *testing.T) {
|
|||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c, err := dockerfile.New(dockerfile.Options{
|
||||
c, err := New(Options{
|
||||
Filename: tt.dfile,
|
||||
})
|
||||
if tt.wantErr {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package dockerfile_test
|
||||
package dockerfile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/dockerfile"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFromImages(t *testing.T) {
|
||||
c, err := dockerfile.New(dockerfile.Options{
|
||||
c, err := New(Options{
|
||||
Filename: "./fixtures/valid.Dockerfile",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
package registry_test
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseImage(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
parseOpts registry.ParseImageOptions
|
||||
expected registry.Image
|
||||
parseOpts ParseImageOptions
|
||||
expected Image
|
||||
}{
|
||||
{
|
||||
desc: "bintray artifactory-oss",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "jfrog-docker-reg2.bintray.io/jfrog/artifactory-oss:4.0.0",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "jfrog-docker-reg2.bintray.io",
|
||||
Path: "jfrog/artifactory-oss",
|
||||
Tag: "4.0.0",
|
||||
|
@ -26,10 +25,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "bintray xray-server",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "docker.bintray.io/jfrog/xray-server:2.8.6",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "docker.bintray.io",
|
||||
Path: "jfrog/xray-server",
|
||||
Tag: "2.8.6",
|
||||
|
@ -37,10 +36,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "dockerhub alpine",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "alpine",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "docker.io",
|
||||
Path: "library/alpine",
|
||||
Tag: "latest",
|
||||
|
@ -48,10 +47,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "dockerhub crazymax/nextcloud",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "docker.io/crazymax/nextcloud:latest",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "docker.io",
|
||||
Path: "crazymax/nextcloud",
|
||||
Tag: "latest",
|
||||
|
@ -59,10 +58,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "gcr busybox",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "gcr.io/google-containers/busybox:latest",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "gcr.io",
|
||||
Path: "google-containers/busybox",
|
||||
Tag: "latest",
|
||||
|
@ -70,10 +69,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "github ddns-route53",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "docker.pkg.github.com/crazy-max/ddns-route53/ddns-route53:latest",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "docker.pkg.github.com",
|
||||
Path: "crazy-max/ddns-route53/ddns-route53",
|
||||
Tag: "latest",
|
||||
|
@ -81,10 +80,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "gitlab meltano",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "registry.gitlab.com/meltano/meltano",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "registry.gitlab.com",
|
||||
Path: "meltano/meltano",
|
||||
Tag: "latest",
|
||||
|
@ -92,10 +91,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "quay hypercube",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "quay.io/coreos/hyperkube",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "quay.io",
|
||||
Path: "coreos/hyperkube",
|
||||
Tag: "latest",
|
||||
|
@ -103,10 +102,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "ghcr ddns-route53",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "ghcr.io/crazy-max/ddns-route53",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "ghcr.io",
|
||||
Path: "crazy-max/ddns-route53",
|
||||
Tag: "latest",
|
||||
|
@ -114,10 +113,10 @@ func TestParseImage(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "ghcr radarr",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "ghcr.io/linuxserver/radarr",
|
||||
},
|
||||
expected: registry.Image{
|
||||
expected: Image{
|
||||
Domain: "ghcr.io",
|
||||
Path: "linuxserver/radarr",
|
||||
Tag: "latest",
|
||||
|
@ -128,7 +127,7 @@ func TestParseImage(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
tt := tt
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
img, err := registry.ParseImage(tt.parseOpts)
|
||||
img, err := ParseImage(tt.parseOpts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -142,96 +141,96 @@ func TestParseImage(t *testing.T) {
|
|||
func TestHubLink(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
parseOpts registry.ParseImageOptions
|
||||
parseOpts ParseImageOptions
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "bintray artifactory-oss",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "jfrog-docker-reg2.bintray.io/jfrog/artifactory-oss:4.0.0",
|
||||
},
|
||||
expected: "https://bintray.com/jfrog/reg2/jfrog%3Aartifactory-oss",
|
||||
},
|
||||
{
|
||||
desc: "bintray kubexray",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "jfrog-docker-reg2.bintray.io/kubexray:latest",
|
||||
},
|
||||
expected: "https://bintray.com/jfrog/reg2/kubexray",
|
||||
},
|
||||
{
|
||||
desc: "bintray xray-server",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "docker.bintray.io/jfrog/xray-server:2.8.6",
|
||||
},
|
||||
expected: "https://bintray.com/jfrog/reg2/jfrog%3Axray-server",
|
||||
},
|
||||
{
|
||||
desc: "dockerhub alpine",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "alpine",
|
||||
},
|
||||
expected: "https://hub.docker.com/_/alpine",
|
||||
},
|
||||
{
|
||||
desc: "dockerhub crazymax/nextcloud",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "docker.io/crazymax/nextcloud:latest",
|
||||
},
|
||||
expected: "https://hub.docker.com/r/crazymax/nextcloud",
|
||||
},
|
||||
{
|
||||
desc: "gcr busybox",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "gcr.io/google-containers/busybox:latest",
|
||||
},
|
||||
expected: "https://gcr.io/google-containers/busybox",
|
||||
},
|
||||
{
|
||||
desc: "github ddns-route53",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "docker.pkg.github.com/crazy-max/ddns-route53/ddns-route53:latest",
|
||||
},
|
||||
expected: "https://github.com/crazy-max/ddns-route53/packages",
|
||||
},
|
||||
{
|
||||
desc: "gitlab meltano",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "registry.gitlab.com/meltano/meltano",
|
||||
},
|
||||
expected: "https://gitlab.com/meltano/meltano/container_registry",
|
||||
},
|
||||
{
|
||||
desc: "quay hypercube",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "quay.io/coreos/hyperkube",
|
||||
},
|
||||
expected: "https://quay.io/repository/coreos/hyperkube",
|
||||
},
|
||||
{
|
||||
desc: "ghcr ddns-route53",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "ghcr.io/crazy-max/ddns-route53",
|
||||
},
|
||||
expected: "https://github.com/users/crazy-max/packages/container/package/ddns-route53",
|
||||
},
|
||||
{
|
||||
desc: "ghcr radarr",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "ghcr.io/linuxserver/radarr",
|
||||
},
|
||||
expected: "https://github.com/users/linuxserver/packages/container/package/radarr",
|
||||
},
|
||||
{
|
||||
desc: "redhat etcd",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "registry.access.redhat.com/rhel7/etcd",
|
||||
},
|
||||
expected: "https://access.redhat.com/containers/#/registry.access.redhat.com/rhel7/etcd",
|
||||
},
|
||||
{
|
||||
desc: "private",
|
||||
parseOpts: registry.ParseImageOptions{
|
||||
parseOpts: ParseImageOptions{
|
||||
Name: "myregistry.example.com/an/image:latest",
|
||||
HubTpl: "https://{{ .Domain }}/ui/repos/{{ .Path }}",
|
||||
},
|
||||
|
@ -242,7 +241,7 @@ func TestHubLink(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
tt := tt
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
img, err := registry.ParseImage(tt.parseOpts)
|
||||
img, err := ParseImage(tt.parseOpts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -1,29 +1,28 @@
|
|||
package registry_test
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCompareDigest(t *testing.T) {
|
||||
t.Parallel()
|
||||
rc, err := registry.New(registry.Options{
|
||||
rc, err := New(Options{
|
||||
CompareDigest: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
img, err := registry.ParseImage(registry.ParseImageOptions{
|
||||
img, err := ParseImage(ParseImageOptions{
|
||||
Name: "crazymax/diun:2.5.0",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
manifest, _, err := rc.Manifest(img, registry.Manifest{
|
||||
manifest, _, err := rc.Manifest(img, Manifest{
|
||||
Name: "docker.io/crazymax/diun",
|
||||
Tag: "2.5.0",
|
||||
MIMEType: "application/vnd.docker.distribution.manifest.list.v2+json",
|
||||
|
@ -40,7 +39,7 @@ func TestCompareDigest(t *testing.T) {
|
|||
|
||||
func TestManifest(t *testing.T) {
|
||||
t.Parallel()
|
||||
rc, err := registry.New(registry.Options{
|
||||
rc, err := New(Options{
|
||||
CompareDigest: true,
|
||||
ImageOs: "linux",
|
||||
ImageArch: "amd64",
|
||||
|
@ -49,14 +48,14 @@ func TestManifest(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
img, err := registry.ParseImage(registry.ParseImageOptions{
|
||||
img, err := ParseImage(ParseImageOptions{
|
||||
Name: "portainer/portainer-ce:linux-amd64-2.5.1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
manifest, updated, err := rc.Manifest(img, registry.Manifest{
|
||||
manifest, updated, err := rc.Manifest(img, Manifest{
|
||||
Name: "docker.io/portainer/portainer-ce",
|
||||
Tag: "linux-amd64-2.5.1",
|
||||
MIMEType: "application/vnd.docker.distribution.manifest.v2+json",
|
||||
|
@ -101,7 +100,7 @@ func TestManifest(t *testing.T) {
|
|||
|
||||
func TestManifestMultiUpdatedPlatform(t *testing.T) {
|
||||
t.Parallel()
|
||||
rc, err := registry.New(registry.Options{
|
||||
rc, err := New(Options{
|
||||
CompareDigest: true,
|
||||
ImageOs: "linux",
|
||||
ImageArch: "amd64",
|
||||
|
@ -110,14 +109,14 @@ func TestManifestMultiUpdatedPlatform(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
img, err := registry.ParseImage(registry.ParseImageOptions{
|
||||
img, err := ParseImage(ParseImageOptions{
|
||||
Name: "mongo:3.6.21",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
manifest, updated, err := rc.Manifest(img, registry.Manifest{
|
||||
manifest, updated, err := rc.Manifest(img, Manifest{
|
||||
Name: "docker.io/library/mongo",
|
||||
Tag: "3.6.21",
|
||||
MIMEType: "application/vnd.docker.distribution.manifest.list.v2+json",
|
||||
|
@ -181,7 +180,7 @@ func TestManifestMultiUpdatedPlatform(t *testing.T) {
|
|||
|
||||
func TestManifestMultiNotUpdatedPlatform(t *testing.T) {
|
||||
t.Parallel()
|
||||
rc, err := registry.New(registry.Options{
|
||||
rc, err := New(Options{
|
||||
CompareDigest: true,
|
||||
ImageOs: "linux",
|
||||
ImageArch: "amd64",
|
||||
|
@ -190,14 +189,14 @@ func TestManifestMultiNotUpdatedPlatform(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
img, err := registry.ParseImage(registry.ParseImageOptions{
|
||||
img, err := ParseImage(ParseImageOptions{
|
||||
Name: "mongo:3.6.21",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
manifest, updated, err := rc.Manifest(img, registry.Manifest{
|
||||
manifest, updated, err := rc.Manifest(img, Manifest{
|
||||
Name: "docker.io/library/mongo",
|
||||
Tag: "3.6.21",
|
||||
MIMEType: "application/vnd.docker.distribution.manifest.list.v2+json",
|
||||
|
@ -261,7 +260,7 @@ func TestManifestMultiNotUpdatedPlatform(t *testing.T) {
|
|||
|
||||
func TestManifestVariant(t *testing.T) {
|
||||
t.Parallel()
|
||||
rc, err := registry.New(registry.Options{
|
||||
rc, err := New(Options{
|
||||
ImageOs: "linux",
|
||||
ImageArch: "arm",
|
||||
ImageVariant: "v7",
|
||||
|
@ -270,14 +269,14 @@ func TestManifestVariant(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
|
||||
img, err := registry.ParseImage(registry.ParseImageOptions{
|
||||
img, err := ParseImage(ParseImageOptions{
|
||||
Name: "crazymax/diun:2.5.0",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
manifest, _, err := rc.Manifest(img, registry.Manifest{})
|
||||
manifest, _, err := rc.Manifest(img, Manifest{})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "docker.io/crazymax/diun", manifest.Name)
|
||||
assert.Equal(t, "2.5.0", manifest.Tag)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package registry_test
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -54,7 +53,7 @@ func TestParseReference(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
tt := tt
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
ref, err := registry.ParseReference(tt.input)
|
||||
ref, err := ParseReference(tt.input)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
package registry_test
|
||||
package registry
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
rc *registry.Client
|
||||
rc *Client
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
|
||||
rc, err = registry.New(registry.Options{
|
||||
rc, err = New(Options{
|
||||
ImageOs: "linux",
|
||||
ImageArch: "amd64",
|
||||
})
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
package registry_test
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/crazy-max/diun/v4/pkg/registry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTags(t *testing.T) {
|
||||
assert.NotNil(t, rc)
|
||||
|
||||
image, err := registry.ParseImage(registry.ParseImageOptions{
|
||||
image, err := ParseImage(ParseImageOptions{
|
||||
Name: "crazymax/diun:3.0.0",
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
tags, err := rc.Tags(registry.TagsOptions{
|
||||
tags, err := rc.Tags(TagsOptions{
|
||||
Image: image,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -31,12 +30,12 @@ func TestTags(t *testing.T) {
|
|||
func TestTagsSort(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
sortTag registry.SortTag
|
||||
sortTag SortTag
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "sort default",
|
||||
sortTag: registry.SortTagDefault,
|
||||
sortTag: SortTagDefault,
|
||||
expected: []string{
|
||||
"0.1.0",
|
||||
"0.4.0",
|
||||
|
@ -76,7 +75,7 @@ func TestTagsSort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "sort lexicographical",
|
||||
sortTag: registry.SortTagLexicographical,
|
||||
sortTag: SortTagLexicographical,
|
||||
expected: []string{
|
||||
"0.1.0",
|
||||
"0.4.0",
|
||||
|
@ -116,7 +115,7 @@ func TestTagsSort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "sort reverse",
|
||||
sortTag: registry.SortTagReverse,
|
||||
sortTag: SortTagReverse,
|
||||
expected: []string{
|
||||
"latest",
|
||||
"edge",
|
||||
|
@ -156,7 +155,7 @@ func TestTagsSort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "sort semver",
|
||||
sortTag: registry.SortTagSemver,
|
||||
sortTag: SortTagSemver,
|
||||
expected: []string{
|
||||
"alpine-5.0",
|
||||
"ubuntu-5.0",
|
||||
|
@ -237,7 +236,7 @@ func TestTagsSort(t *testing.T) {
|
|||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tags := registry.SortTags(repotags, tt.sortTag)
|
||||
tags := SortTags(repotags, tt.sortTag)
|
||||
assert.Equal(t, tt.expected, tags)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue