Skip to content

Commit

Permalink
remove dependence on user.Current in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Sep 11, 2018
1 parent 6ceefc0 commit 62a813b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ COPY assets/ /assets
RUN go build -o /assets/check github.com/concourse/docker-image-resource/cmd/check
RUN go build -o /assets/print-metadata github.com/concourse/docker-image-resource/cmd/print-metadata
RUN go build -o /assets/ecr-login github.com/concourse/docker-image-resource/vendor/github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cmd
ENV CGO_ENABLED 1
RUN set -e; \
for pkg in $(go list ./...); do \
go test -o "/tests/$(basename $pkg).test" -c $pkg; \
Expand Down
18 changes: 6 additions & 12 deletions cmd/print-metadata/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"os"
"os/exec"
"os/user"
"runtime"
"syscall"

Expand All @@ -23,9 +22,8 @@ type imageMetadata struct {

var _ = Describe("print-metadata", func() {
var (
cmd *exec.Cmd
userFile *os.File
currentUserName string
cmd *exec.Cmd
userFile *os.File

metadata imageMetadata
)
Expand Down Expand Up @@ -60,25 +58,21 @@ var _ = Describe("print-metadata", func() {

Context("when password file contains current user", func() {
BeforeEach(func() {
currentUser, err := user.Current()
Expect(err).NotTo(HaveOccurred())

currentUserName = currentUser.Username
currentUsedID := syscall.Getuid()

_, err = userFile.WriteString(fmt.Sprintf(
_, err := userFile.WriteString(fmt.Sprintf(
"%s:*:%d:%d:System Administrator:/var/%s:/bin/sh\n",
currentUserName,
"some-user",
currentUsedID,
currentUsedID,
currentUserName,
"some-user",
))
Expect(err).NotTo(HaveOccurred())
userFile.Sync()
})

It("sets current user in metadata", func() {
Expect(metadata.User).To(Equal(currentUserName))
Expect(metadata.User).To(Equal("some-user"))
})
})
})
Expand Down

0 comments on commit 62a813b

Please sign in to comment.