2022-10-27 02:21:07 +00:00
|
|
|
package compiler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/strslice"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecretAvailable(t *testing.T) {
|
|
|
|
secret := Secret{
|
|
|
|
Match: []string{"golang"},
|
|
|
|
PluginOnly: false,
|
|
|
|
}
|
|
|
|
assert.True(t, secret.Available(&yaml.Container{
|
|
|
|
Image: "golang",
|
2023-02-01 23:08:02 +00:00
|
|
|
Commands: types.StringOrSlice(strslice.StrSlice{"echo 'this is not a plugin'"}),
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
|
|
|
assert.False(t, secret.Available(&yaml.Container{
|
|
|
|
Image: "not-golang",
|
2023-02-01 23:08:02 +00:00
|
|
|
Commands: types.StringOrSlice(strslice.StrSlice{"echo 'this is not a plugin'"}),
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
|
|
|
// secret only available for "golang" plugin
|
|
|
|
secret = Secret{
|
|
|
|
Match: []string{"golang"},
|
|
|
|
PluginOnly: true,
|
|
|
|
}
|
|
|
|
assert.True(t, secret.Available(&yaml.Container{
|
|
|
|
Image: "golang",
|
2023-02-01 23:08:02 +00:00
|
|
|
Commands: types.StringOrSlice(strslice.StrSlice{}),
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
|
|
|
assert.False(t, secret.Available(&yaml.Container{
|
|
|
|
Image: "not-golang",
|
2023-02-01 23:08:02 +00:00
|
|
|
Commands: types.StringOrSlice(strslice.StrSlice{}),
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
|
|
|
assert.False(t, secret.Available(&yaml.Container{
|
|
|
|
Image: "not-golang",
|
2023-02-01 23:08:02 +00:00
|
|
|
Commands: types.StringOrSlice(strslice.StrSlice{"echo 'this is not a plugin'"}),
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
|
|
|
}
|