This repository has been archived on 2025-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
Files
drone-runner-podman/internal/match/match_test.go
Javier Palomo be90c9afe1 Test that inverse matches work for DRONE_LIMIT_REPOS
Added some additional unit tests to verify that `DRONE_LIMIT_REPOS`
works for inverse matches. Given that the matching is based on
path/filepath, inverse matches are supported.

Related docs:
https://docs.drone.io/runner/docker/configuration/reference/drone-limit-repos/
2021-04-13 12:39:39 +02:00

150 lines
3.4 KiB
Go

// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.
package match
import (
"testing"
"github.com/drone/drone-go/drone"
)
func TestFunc(t *testing.T) {
tests := []struct {
repo string
event string
trusted bool
match bool
matcher func(*drone.Repo, *drone.Build) bool
}{
//
// Expect match true
//
// repository, event and trusted flag matching
{
repo: "octocat/hello-world",
event: "push",
trusted: true,
match: true,
matcher: Func([]string{"spaceghost/*", "octocat/*"}, []string{"push"}, true),
},
// repository matching
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: false,
match: true,
matcher: Func([]string{"spaceghost/*", "octocat/*"}, []string{}, false),
},
// repository matching, skipping an org
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: false,
match: true,
matcher: Func([]string{"!spaceghost/*", "octocat/*"}, []string{}, false),
},
// event matching
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: false,
match: true,
matcher: Func([]string{}, []string{"pull_request"}, false),
},
// trusted flag matching
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: true,
match: true,
matcher: Func([]string{}, []string{}, true),
},
//
// Expect match false
//
// repository matching
{
repo: "spaceghost/hello-world",
event: "pull_request",
trusted: false,
match: false,
matcher: Func([]string{"octocat/*"}, []string{}, false),
},
// repository matching, skip all repos in the org
{
repo: "spaceghost/hello-world",
event: "pull_request",
trusted: false,
match: false,
matcher: Func([]string{"!spaceghost/*"}, []string{}, false),
},
// repository matching, skip a concrete repo
{
repo: "spaceghost/hello-world",
event: "pull_request",
trusted: false,
match: false,
matcher: Func([]string{"!spaceghost/hello-world"}, []string{}, false),
},
// event matching
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: false,
match: false,
matcher: Func([]string{}, []string{"push"}, false),
},
// trusted flag matching
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: false,
match: false,
matcher: Func([]string{}, []string{}, true),
},
// does not match repository
{
repo: "foo/hello-world",
event: "push",
trusted: true,
match: false,
matcher: Func([]string{"spaceghost/*", "octocat/*"}, []string{"push"}, true),
},
// does not match event
{
repo: "octocat/hello-world",
event: "pull_request",
trusted: true,
match: false,
matcher: Func([]string{"spaceghost/*", "octocat/*"}, []string{"push"}, true),
},
// does not match trusted flag
{
repo: "octocat/hello-world",
event: "push",
trusted: false,
match: false,
matcher: Func([]string{"spaceghost/*", "octocat/*"}, []string{"push"}, true),
},
}
for i, test := range tests {
repo := &drone.Repo{
Slug: test.repo,
Trusted: test.trusted,
}
build := &drone.Build{
Event: test.event,
}
match := test.matcher(repo, build)
if match != test.match {
t.Errorf("Expect match %v at index %d", test.match, i)
}
}
}