This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprofile_test.go
69 lines (64 loc) · 1.82 KB
/
profile_test.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 ekino. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package godim
import (
"testing"
)
const (
h = "handler"
s = "service"
r = "repository"
d = "driver"
)
func TestNewHTTPStrict(t *testing.T) {
ap := StrictHTTPAppProfile()
if len(ap.profiles) != 4 {
t.Fatalf("wrong number of profiles")
}
if ap.profiles[h].canBeInjectedIn(s) {
t.Fatalf("handler can't be injected in services")
}
if ap.profiles[h].canBeInjectedIn(r) {
t.Fatalf("handler can't be injected in repositories")
}
if ap.profiles[h].canBeInjectedIn(h) {
t.Fatalf("handler can't be injected in handlers")
}
if !ap.profiles[s].canBeInjectedIn(h) {
t.Fatalf("service must be injectable in handlers")
}
if ap.profiles[s].canBeInjectedIn(s) {
t.Fatalf("service can't be injected in services")
}
if ap.profiles[s].canBeInjectedIn(r) {
t.Fatalf("service can't be injected in repositories")
}
if !ap.profiles[r].canBeInjectedIn(s) {
t.Fatalf("repository must be injectable in services")
}
if ap.profiles[r].canBeInjectedIn(h) {
t.Fatalf("repository can't be injected in handlers")
}
if ap.profiles[r].canBeInjectedIn(r) {
t.Fatalf("repository can't be injected in repositories")
}
if !ap.profiles[d].canBeInjectedIn(r) {
t.Fatalf("driver must be injectable in repository")
}
if ap.profiles[d].canBeInjectedIn(s) || ap.profiles[d].canBeInjectedIn(d) || ap.profiles[d].canBeInjectedIn(h) {
t.Fatalf("driver can't be injected anywhere else than repository")
}
if !ap.isLocked() {
t.Fatalf("strict profile must be locked")
}
}
func TestHttpProfile(t *testing.T) {
ap := HTTPAppProfile()
if len(ap.profiles) != 3 {
t.Fatalf("wrong number of profiles")
}
if !ap.profiles[s].canBeInjectedIn(s) {
t.Fatalf("services should be injected in services")
}
}