fce3289743
Implements #30, allows setting a (single) tag to override the default of `latest` allows for the woodpecker-ci usecase of setting `next` as the tag for the default branch. Co-authored-by: Gapodo <gapodo@datenclown.at> Reviewed-on: https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/pulls/36 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: gapodo <gapodo@geekvoid.net> Co-committed-by: gapodo <gapodo@geekvoid.net>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
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{
|
|
Context: ".",
|
|
Tags: *cli.NewStringSlice("latest"),
|
|
TagsDefaultName: "latest",
|
|
LabelsAuto: true,
|
|
Pull: true,
|
|
},
|
|
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)
|
|
}
|
|
}
|