aboutsummaryrefslogtreecommitdiff
path: root/internal/confyg/allower_test.go
blob: 1cae7acbb7707939da8754ad5afa66a4216cd608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package confyg

import (
	"fmt"
	"testing"
)

func TestAllower(t *testing.T) {
	al := AllowerFunc(func(verb string, block bool) bool {
		switch verb {
		case "project":
			if block {
				return false
			}

			return true
		}

		return false
	})

	cases := []struct {
		verb  string
		block bool
		want  bool
	}{
		{
			verb:  "project",
			block: false,
			want:  true,
		},
		{
			verb:  "nonsense",
			block: true,
			want:  false,
		},
	}

	for _, cs := range cases {
		t.Run(fmt.Sprint(cs), func(t *testing.T) {
			result := al.Allow(cs.verb, cs.block)

			if result != cs.want {
				t.Fatalf("wanted Allow(%q, %v) == %v, got: %v", cs.verb, cs.block, cs.want, result)
			}
		})
	}
}