2022-10-27 02:21:07 +00:00
|
|
|
package compiler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-06-06 07:14:21 +00:00
|
|
|
|
|
|
|
yaml_types "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
|
|
|
|
yaml_base_types "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base"
|
2022-10-27 02:21:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecretAvailable(t *testing.T) {
|
|
|
|
secret := Secret{
|
|
|
|
Match: []string{"golang"},
|
|
|
|
PluginOnly: false,
|
|
|
|
}
|
2023-06-06 07:14:21 +00:00
|
|
|
assert.True(t, secret.Available(&yaml_types.Container{
|
2022-10-27 02:21:07 +00:00
|
|
|
Image: "golang",
|
2023-06-06 07:14:21 +00:00
|
|
|
Commands: yaml_base_types.StringOrSlice{"echo 'this is not a plugin'"},
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
2023-06-06 07:14:21 +00:00
|
|
|
assert.False(t, secret.Available(&yaml_types.Container{
|
2022-10-27 02:21:07 +00:00
|
|
|
Image: "not-golang",
|
2023-06-06 07:14:21 +00:00
|
|
|
Commands: yaml_base_types.StringOrSlice{"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,
|
|
|
|
}
|
2023-06-06 07:14:21 +00:00
|
|
|
assert.True(t, secret.Available(&yaml_types.Container{
|
2022-10-27 02:21:07 +00:00
|
|
|
Image: "golang",
|
2023-06-06 07:14:21 +00:00
|
|
|
Commands: yaml_base_types.StringOrSlice{},
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
2023-06-06 07:14:21 +00:00
|
|
|
assert.False(t, secret.Available(&yaml_types.Container{
|
2022-10-27 02:21:07 +00:00
|
|
|
Image: "not-golang",
|
2023-06-06 07:14:21 +00:00
|
|
|
Commands: yaml_base_types.StringOrSlice{},
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
2023-06-06 07:14:21 +00:00
|
|
|
assert.False(t, secret.Available(&yaml_types.Container{
|
2022-10-27 02:21:07 +00:00
|
|
|
Image: "not-golang",
|
2023-06-06 07:14:21 +00:00
|
|
|
Commands: yaml_base_types.StringOrSlice{"echo 'this is not a plugin'"},
|
2022-10-27 02:21:07 +00:00
|
|
|
}))
|
|
|
|
}
|