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

Commit

Permalink
Merge pull request #13 from oracle/fixes
Browse files Browse the repository at this point in the history
Adds missing test and fixes cleanup of build dir
  • Loading branch information
vishvananda authored Jul 24, 2017
2 parents 73ccce7 + e2691f0 commit 6e2cd85
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
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)
}
}
}

0 comments on commit 6e2cd85

Please sign in to comment.