|
1 |
| -.PHONY: default install build test quicktest fmt vet lint |
| 1 | +.PHONY: default install build test quicktest fmt vet lint |
2 | 2 |
|
3 |
| -# List of all release tags "supported" by our current Go version |
4 |
| -# E.g. ":go1.1:go1.2:go1.3:go1.4:go1.5:go1.6:go1.7:go1.8:go1.9:go1.10:go1.11:go1.12:" |
5 |
| -GO_RELEASE_TAGS := $(shell go list -f ':{{join (context.ReleaseTags) ":"}}:' runtime) |
| 3 | +default: fmt vet lint build quicktest |
6 | 4 |
|
7 |
| -# Only use the `-race` flag on newer versions of Go (version 1.3 and newer) |
8 |
| -ifeq (,$(findstring :go1.3:,$(GO_RELEASE_TAGS))) |
9 |
| - RACE_FLAG := |
10 |
| -else |
11 |
| - RACE_FLAG := -race -cpu 1,2,4 |
| 5 | +CONTAINER_CMD := $(shell command -v podman 2>/dev/null) |
| 6 | +ifeq ($(CONTAINER_CMD),) |
| 7 | + CONTAINER_CMD := $(shell command -v docker 2>/dev/null) |
12 | 8 | endif
|
13 | 9 |
|
14 |
| -# Run `go vet` on Go 1.12 and newer. For Go 1.5-1.11, use `go tool vet` |
15 |
| -ifneq (,$(findstring :go1.12:,$(GO_RELEASE_TAGS))) |
16 |
| - GO_VET := go vet \ |
17 |
| - -atomic \ |
18 |
| - -bool \ |
19 |
| - -copylocks \ |
20 |
| - -nilfunc \ |
21 |
| - -printf \ |
22 |
| - -rangeloops \ |
23 |
| - -unreachable \ |
24 |
| - -unsafeptr \ |
25 |
| - -unusedresult \ |
26 |
| - . |
27 |
| -else ifneq (,$(findstring :go1.5:,$(GO_RELEASE_TAGS))) |
28 |
| - GO_VET := go tool vet \ |
29 |
| - -atomic \ |
30 |
| - -bool \ |
31 |
| - -copylocks \ |
32 |
| - -nilfunc \ |
33 |
| - -printf \ |
34 |
| - -shadow \ |
35 |
| - -rangeloops \ |
36 |
| - -unreachable \ |
37 |
| - -unsafeptr \ |
38 |
| - -unusedresult \ |
39 |
| - . |
40 |
| -else |
41 |
| - GO_VET := @echo "go vet skipped -- not supported on this version of Go" |
| 10 | +# Check if we found either command |
| 11 | +ifeq ($(CONTAINER_CMD),) |
| 12 | + $(error Neither podman nor docker found in PATH) |
42 | 13 | endif
|
43 | 14 |
|
44 |
| -default: fmt vet lint build quicktest |
45 |
| - |
46 | 15 | install:
|
47 | 16 | go get -t -v ./...
|
48 | 17 |
|
49 | 18 | build:
|
50 | 19 | go build -v ./...
|
51 | 20 |
|
52 |
| -test: |
53 |
| - go test -v $(RACE_FLAG) -cover ./... |
| 21 | +LDAP_ADMIN_DN := cn=admin,dc=example,dc=com |
| 22 | +LDAP_ADMIN_PASSWORD := admin123 |
| 23 | +LDAP_BASE_DN := dc=example,dc=com |
| 24 | +LDAP_URL := ldap://127.0.0.1:389 |
| 25 | +CONTAINER_NAME := go-ldap-test |
| 26 | + |
| 27 | +local-server: |
| 28 | + -$(CONTAINER_CMD) rm -f -t 10 $(CONTAINER_NAME) |
| 29 | + $(CONTAINER_CMD) \ |
| 30 | + run \ |
| 31 | + --rm \ |
| 32 | + -d \ |
| 33 | + --name $(CONTAINER_NAME) \ |
| 34 | + --hostname "$(CONTAINER_NAME).example.com" \ |
| 35 | + -p "127.0.0.1:3389:389" \ |
| 36 | + -p "127.0.0.1:3636:636" \ |
| 37 | + -e LDAP_ORGANISATION="Example Inc" \ |
| 38 | + -e LDAP_DOMAIN="example.com" \ |
| 39 | + -e LDAP_ADMIN_PASSWORD="$(LDAP_ADMIN_PASSWORD)" \ |
| 40 | + -e LDAP_TLS_VERIFY_CLIENT="never" \ |
| 41 | + docker.io/osixia/openldap:1.5.0 |
| 42 | + |
| 43 | + @echo "Waiting for LDAP server to be ready..." |
| 44 | + @$(CONTAINER_CMD) exec $(CONTAINER_NAME) /bin/sh -c 'until ldapsearch -x -H $(LDAP_URL) -b "$(LDAP_BASE_DN)" -D "$(LDAP_ADMIN_DN)" -w $(LDAP_ADMIN_PASSWORD) > /dev/null 2>&1; do echo "LDAP server not ready yet, waiting..."; sleep 2; done' |
| 45 | + @echo "LDAP server is ready!" |
| 46 | + |
| 47 | + @echo "Configuring anonymous access..." |
| 48 | + @$(CONTAINER_CMD) exec $(CONTAINER_NAME) /bin/sh -c 'echo "dn: olcDatabase={1}mdb,cn=config\nchangetype: modify\nreplace: olcAccess\nolcAccess: {0}to * by * read" | ldapmodify -Y EXTERNAL -H ldapi:///' |
| 49 | + |
| 50 | + $(CONTAINER_CMD) cp -a ./testdata $(CONTAINER_NAME):/ |
| 51 | + @echo "Loading LDIF files..." |
| 52 | + @$(CONTAINER_CMD) exec $(CONTAINER_NAME) /bin/sh -c 'for file in /testdata/*.ldif; do echo "Processing $$file..."; cat "$$file" | ldapadd -v -x -H $(LDAP_URL) -D "$(LDAP_ADMIN_DN)" -w $(LDAP_ADMIN_PASSWORD); done' |
| 53 | + |
| 54 | +delete-container: |
| 55 | + -$(CONTAINER_CMD) rm -f -t 10 $(CONTAINER_NAME) |
54 | 56 |
|
55 | 57 | quicktest:
|
56 | 58 | go test ./...
|
|
71 | 73 | fi
|
72 | 74 |
|
73 | 75 | vet:
|
74 |
| - $(GO_VET) |
| 76 | + go vet \ |
| 77 | + -atomic \ |
| 78 | + -bool \ |
| 79 | + -copylocks \ |
| 80 | + -nilfunc \ |
| 81 | + -printf \ |
| 82 | + -rangeloops \ |
| 83 | + -unreachable \ |
| 84 | + -unsafeptr \ |
| 85 | + -unusedresult \ |
| 86 | + ./... |
75 | 87 |
|
76 | 88 | # https://github.com/golang/lint
|
77 | 89 | # go get github.com/golang/lint/golint
|
|
0 commit comments