2022-10-11 09:38:36 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"codeberg.org/6543/go-yaml2json"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultSettings = Settings{
|
|
|
|
Daemon: Daemon{
|
|
|
|
StoragePath: "/var/lib/docker",
|
|
|
|
},
|
|
|
|
Build: Build{
|
2022-11-05 02:25:44 +00:00
|
|
|
Context: ".",
|
|
|
|
Tags: *cli.NewStringSlice("latest"),
|
|
|
|
TagsDefaultName: "latest",
|
|
|
|
LabelsAuto: true,
|
|
|
|
Pull: true,
|
2022-10-11 09:38:36 +00:00
|
|
|
},
|
|
|
|
DefaultLogin: Login{
|
|
|
|
Registry: "https://index.docker.io/v1/",
|
|
|
|
},
|
|
|
|
LoginsRaw: "[]",
|
|
|
|
Cleanup: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultLogin(t *testing.T) {
|
|
|
|
s := defaultSettings
|
|
|
|
assert.NoError(t, newSettingsOnly(&s).Validate())
|
|
|
|
if assert.Len(t, s.Logins, 1) {
|
|
|
|
assert.EqualValues(t, defaultSettings.DefaultLogin.Registry, s.Logins[0].Registry)
|
|
|
|
}
|
|
|
|
|
|
|
|
// only use login to auth to registrys
|
|
|
|
loginsRaw, err := yaml2json.Convert([]byte(`
|
|
|
|
- registry: https://index.docker.io/v1/
|
|
|
|
username: docker_username
|
|
|
|
password: docker_password
|
|
|
|
- registry: https://codeberg.org
|
|
|
|
username: cb_username
|
|
|
|
password: cb_password`))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
s.LoginsRaw = string(loginsRaw)
|
|
|
|
assert.NoError(t, newSettingsOnly(&s).Validate())
|
|
|
|
if assert.Len(t, s.Logins, 2) {
|
|
|
|
assert.EqualValues(t, defaultSettings.DefaultLogin.Registry, s.Logins[0].Registry)
|
|
|
|
}
|
|
|
|
|
|
|
|
// mixed login settings ('logins' and 'username', 'password' are used)
|
|
|
|
s = defaultSettings
|
|
|
|
loginsRaw, err = yaml2json.Convert([]byte(`
|
|
|
|
- registry: https://codeberg.org
|
|
|
|
username: cb_username
|
|
|
|
password: cb_password`))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
s.LoginsRaw = string(loginsRaw)
|
|
|
|
s.DefaultLogin.Username = "docker_username"
|
|
|
|
s.DefaultLogin.Password = "docker_password"
|
|
|
|
assert.NoError(t, newSettingsOnly(&s).Validate())
|
|
|
|
if assert.Len(t, s.Logins, 2) {
|
|
|
|
assert.EqualValues(t, defaultSettings.DefaultLogin.Registry, s.Logins[0].Registry)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore default registry
|
|
|
|
s = defaultSettings
|
|
|
|
loginsRaw, err = yaml2json.Convert([]byte(`
|
|
|
|
- registry: https://codeberg.org
|
|
|
|
username: cb_username
|
|
|
|
password: cb_password`))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
s.LoginsRaw = string(loginsRaw)
|
|
|
|
assert.NoError(t, newSettingsOnly(&s).Validate())
|
|
|
|
if assert.Len(t, s.Logins, 1) {
|
|
|
|
assert.EqualValues(t, "https://codeberg.org", s.Logins[0].Registry)
|
|
|
|
}
|
|
|
|
}
|