Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Adds missing test and fixes cleanup of build dir #13

Merged
merged 2 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
smith
rpm
.idea/
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ id = $(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n')
# if it is cloned outside of the gopath. Go's vendor support only works if
# the project is inside the gopath
$(NAME): $(call gofiles,$(DIRS))
rm -rf build
mkdir -p build/src/$(REMOTE)
rm -f build/src/$(REMOTE)/$(NAME) && ln -s ../../../../ build/src/$(REMOTE)/$(NAME)
cd build/src/$(REMOTE)/$(NAME) && CGO_ENABLED=0 GOPATH=$(CURDIR)/build \
GO15VENDOREXPERIMENT=1 go build -a -x -v \
-ldflags '-X "main.ver=$(VERSION)" -X "main.sha=$(sha)" -B 0x$(id)' \
-o $(NAME) . || ( rm -rf build && false )
rm -rf build
-o $(NAME) .

.PHONY: $(call testdirs,$(DIRS))
$(call testdirs,$(DIRS)):
Expand All @@ -51,6 +51,7 @@ test: fmt $(call testdirs,$(DIRS))

clean:
rm -f $(NAME)
rm -rf build
rm -rf rpm

install: all
Expand Down
44 changes: 44 additions & 0 deletions nss_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import "testing"

type parseCase struct {
User string
Uid int
Gid int
U string
G string
Nss bool
}

func TestParseUser(t *testing.T) {
for _, c := range []parseCase{
{"root:root", 0, 0, "root", "root", true},
{"0:0", 0, 0, "root", "root", false},
{"daemon:daemon", 1, 1, "daemon", "daemon", true},
{"1:1", 1, 1, "daemon", "daemon", false},
{"smith:0", 10, 0, "smith", "root", true},
{"0:smith", 0, 10, "root", "smith", true},
{"1000:1000", 1000, 1000, "smith", "smith", false},
{"foo:bar", 10, 10, "foo", "bar", true},
{"foo:1000", 10, 1000, "foo", "smith", true},
{"1000:bar", 1000, 10, "smith", "bar", true},
} {
uid, gid, u, g, nss := ParseUser(c.User)
if uid != c.Uid {
t.Fatalf("Fail %v, uids don't match: %d != %d", c, uid, c.Uid)
}
if gid != c.Gid {
t.Fatalf("Fail %v, gids don't match: %d != %d", c, gid, c.Gid)
}
if u != c.U {
t.Fatalf("Fail %v, users don't match: %s != %s", c, u, c.U)
}
if g != c.G {
t.Fatalf("Fail %v, groups don't match: %s != %s", c, g, c.G)
}
if nss != c.Nss {
t.Fatalf("Fail %v, nss doesn't match: %t != %t", c, nss, c.Nss)
}
}
}