Debian Codegraph @

Makefile

raw
1 .PHONY: default install build test test fmt vet lint
2
3 default: fmt vet lint build test
4
5 CONTAINER_CMD := $(shell (command -v docker 2>/dev/null || command -v podman 2>/dev/null))
6 ifeq ($(CONTAINER_CMD),)
7 $(error Neither podman nor docker found in PATH)
8 endif
9
10 install:
11 go get -t -x ./...
12
13 build:
14 go build -v ./...
15
16 LDAP_ADMIN_DN := cn=admin,dc=example,dc=com
17 LDAP_ADMIN_PASSWORD := admin123
18 LDAP_BASE_DN := dc=example,dc=com
19 LDAP_URL := ldap://127.0.0.1:389
20 CONTAINER_NAME := go-ldap-test
21
22 local-server:
23 -$(CONTAINER_CMD) rm -f $(CONTAINER_NAME)
24 $(CONTAINER_CMD) \
25 run \
26 --rm \
27 -d \
28 --name $(CONTAINER_NAME) \
29 --hostname "$(CONTAINER_NAME).example.com" \
30 -p "127.0.0.1:3389:389" \
31 -p "127.0.0.1:3636:636" \
32 -e LDAP_ORGANISATION="Example Inc" \
33 -e LDAP_DOMAIN="example.com" \
34 -e LDAP_ADMIN_PASSWORD="$(LDAP_ADMIN_PASSWORD)" \
35 -e LDAP_TLS_VERIFY_CLIENT="never" \
36 docker.io/osixia/openldap:1.5.0
37
38 @echo "Waiting for LDAP server to be ready..."
39 @$(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'
40 @echo "LDAP server is ready!"
41
42 @echo "Configuring anonymous access..."
43 @$(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:///'
44
45 $(CONTAINER_CMD) cp -a ./testdata $(CONTAINER_NAME):/
46 @echo "Loading LDIF files..."
47 @$(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'
48
49 stop-local-server:
50 -$(CONTAINER_CMD) rm -f -t 10 $(CONTAINER_NAME)
51
52 test:
53 go test -v -cover -race -count=1 .
54
55 fuzz:
56 (cd v3 && go test -fuzz=FuzzGetLDAPError -fuzztime=600s .)
57
58 # Capture output and force failure when there is non-empty output
59 fmt:
60 @echo gofmt -l .
61 @OUTPUT=`gofmt -l . 2>&1`; \
62 if [ "$$OUTPUT" ]; then \
63 echo "gofmt must be run on the following files:"; \
64 echo "$$OUTPUT"; \
65 exit 1; \
66 fi
67
68 vet:
69 go vet \
70 -atomic \
71 -bool \
72 -copylocks \
73 -nilfunc \
74 -printf \
75 -rangeloops \
76 -unreachable \
77 -unsafeptr \
78 -unusedresult \
79 ./...
80
81 # https://github.com/golang/lint
82 # go get github.com/golang/lint/golint
83 # Capture output and force failure when there is non-empty output
84 # Only run on go1.5+
85 lint:
86 @echo golint ./...
87 @OUTPUT=`command -v golint >/dev/null 2>&1 && golint ./... 2>&1`; \
88 if [ "$$OUTPUT" ]; then \
89 echo "golint errors:"; \
90 echo "$$OUTPUT"; \
91 exit 1; \
92 fi