Skip to content

Commit

Permalink
Add support for golang
Browse files Browse the repository at this point in the history
  • Loading branch information
kapillamba4 committed Jul 11, 2018
1 parent 11d5e20 commit a3de075
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Currently we have following images -
- [c](containers/c)
- [cpp](containers/cpp)
- [c#](containers/csharp)
- [golang](containers/golang)
- [java8](containers/java8)
- [nodejs6](containers/nodejs6)
- [nodejs](containers/nodejs8)
Expand Down
9 changes: 9 additions & 0 deletions containers/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM frolvlad/alpine-go

RUN apk add --no-cache bash

COPY ./compile.sh /bin/compile.sh
COPY ./run.sh /bin/run.sh

RUN chmod 777 /bin/compile.sh; \
chmod 777 /bin/run.sh
1 change: 1 addition & 0 deletions containers/golang/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env bash
4 changes: 4 additions & 0 deletions containers/golang/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

chmod 777 program.go
go run program.go < run.stdin 1> run.stdout 2> run.stderr
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
bash tests/csharp/test_worker.sh
}

@test "test golang" {
bash tests/golang/test_worker.sh
}

@test "test java8" {
bash tests/java8/test_worker.sh
}
Expand Down
9 changes: 9 additions & 0 deletions tests/golang/program.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main;

import "fmt";

func main() {
var input string
fmt.Scanf("%s", &input)
fmt.Println("Hello " + input)
}
1 change: 1 addition & 0 deletions tests/golang/run.stdin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
World
38 changes: 38 additions & 0 deletions tests/golang/test_worker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
pushd $(dirname "$0")
DIR=$(pwd)
RUNBOX="${DIR}/runbox"

echo $RUNBOX
# Create runbox
mkdir -p $RUNBOX

# Copy source to runbox
cp $DIR/program.go $RUNBOX/program.go
cp $DIR/run.stdin $RUNBOX/run.stdin

# Test Compile
docker run \
--cpus="1" \
--memory="100m" \
--ulimit nofile=64:64 \
--rm \
--read-only \
-v "$RUNBOX":/usr/src/runbox \
-v "$RUNBOX":/tmp \
-w /usr/src/runbox codingblocks/judge-worker-golang \
bash -c "/bin/compile.sh && /bin/run.sh"

ls -lh ${RUNBOX}

expected="Hello World"
actual="$(cat ${RUNBOX}/run.stdout)"
if [ "$expected" == "$actual" ] ;then
:
else
echo "MISMATCH: Expected = $expected; Actual = $actual"
exit 1
fi

# Delete runbox
rm -rf $RUNBOX

0 comments on commit a3de075

Please sign in to comment.