You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2020/08/13 18:10:46 UTC

[trafficcontrol] branch master updated: Unit test checks (#4948)

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new d0f642e  Unit test checks (#4948)
d0f642e is described below

commit d0f642e29e81bca7c5cf6e3d5c4f0160318e179c
Author: ocket8888 <oc...@apache.org>
AuthorDate: Thu Aug 13 12:10:34 2020 -0600

    Unit test checks (#4948)
    
    * Add CI actions for Go unit tests
    
    * Fixed naming, updated Go version
    
    * Test all-in-one testing
    
    * Commit to all-in-one testing
    
    * Add JoinErrsSep example
    
    * Added Traffic Stats tests
    
    * Pin Go micro version
---
 .github/actions/go-test/Dockerfile    | 23 ++++++++++++++++
 .github/actions/go-test/README.md     | 45 +++++++++++++++++++++++++++++++
 .github/actions/go-test/action.yml    | 28 ++++++++++++++++++++
 .github/actions/go-test/entrypoint.sh | 35 ++++++++++++++++++++++++
 .github/workflows/go.unit.tests.yaml  | 50 +++++++++++++++++++++++++++++++++++
 lib/go-util/join_test.go              | 35 ++++++++++++++++++++++++
 6 files changed, 216 insertions(+)

diff --git a/.github/actions/go-test/Dockerfile b/.github/actions/go-test/Dockerfile
new file mode 100644
index 0000000..524985a
--- /dev/null
+++ b/.github/actions/go-test/Dockerfile
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM golang:1.14.2
+
+COPY entrypoint.sh /entrypoint.sh
+RUN chmod a+x /entrypoint.sh
+
+ENTRYPOINT /entrypoint.sh
diff --git a/.github/actions/go-test/README.md b/.github/actions/go-test/README.md
new file mode 100644
index 0000000..5ea7945
--- /dev/null
+++ b/.github/actions/go-test/README.md
@@ -0,0 +1,45 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+# go-test Docker action
+
+This action runs Go unit tests.
+
+## Inputs
+
+### `dir`
+
+**Required** Directory in which to run tests.
+
+## Outputs
+
+### `result`
+
+Test results.
+
+### `exit-code`
+
+Exit code of the test command
+
+## Example usage
+```yaml
+uses: actions/go-test@v1
+with:
+  dir: './lib/...'
+```
diff --git a/.github/actions/go-test/action.yml b/.github/actions/go-test/action.yml
new file mode 100644
index 0000000..1075f3d
--- /dev/null
+++ b/.github/actions/go-test/action.yml
@@ -0,0 +1,28 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: 'go-test'
+description: 'Runs go tests'
+inputs:
+  dir:  # id of input
+    description: 'Directory in which to run tests'
+    required: true
+runs:
+  using: 'docker'
+  image: 'Dockerfile'
+  args:
+    - ${{ inputs.dir }}
diff --git a/.github/actions/go-test/entrypoint.sh b/.github/actions/go-test/entrypoint.sh
new file mode 100644
index 0000000..ae88dfa
--- /dev/null
+++ b/.github/actions/go-test/entrypoint.sh
@@ -0,0 +1,35 @@
+#!/bin/sh -l
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -e
+
+if [ -z "$INPUT_DIR" ]; then
+	# There's a bug in "defaults" for inputs
+	INPUT_DIR="./lib/..."
+fi
+
+GOPATH="$(mktemp -d)"
+SRCDIR="$GOPATH/src/github.com/apache"
+mkdir -p "$SRCDIR"
+ln -s "$PWD" "$SRCDIR/trafficcontrol"
+cd "$SRCDIR/trafficcontrol"
+
+# Need to fetch golang.org/x/* dependencies
+/usr/local/go/bin/go get -v $INPUT_DIR
+/usr/local/go/bin/go test -v $INPUT_DIR
+exit $?
diff --git a/.github/workflows/go.unit.tests.yaml b/.github/workflows/go.unit.tests.yaml
new file mode 100644
index 0000000..d01525a
--- /dev/null
+++ b/.github/workflows/go.unit.tests.yaml
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Go Unit Tests
+
+on:
+  push:
+    paths:
+      - grove/**.go
+      - lib/**.go
+      - traffic_monitor/**.go
+      - traffic_ops/traffic_ops_golang/**.go
+      - traffic_ops_ort/atstccfg/**.go
+      - traffic_stats/**.go
+  create:
+  pull_request:
+    paths:
+      - grove/**.go
+      - lib/**.go
+      - traffic_monitor/**.go
+      - traffic_ops/traffic_ops_golang/**.go
+      - traffic_ops_ort/atstccfg/**.go
+      - traffic_stats/**.go
+    types: [opened, reopened, edited, synchronize]
+
+jobs:
+  test:
+    runs-on: ubuntu-latest
+
+    steps:
+    - name: Checkout
+      uses: actions/checkout@master
+    - name: Run unit tests
+      uses: ./.github/actions/go-test
+      with:
+        dir: ./grove/... ./lib/... ./traffic_monitor/... ./traffic_ops/traffic_ops_golang/... ./traffic_ops_ort/atstccfg/... ./traffic_stats/...
diff --git a/lib/go-util/join_test.go b/lib/go-util/join_test.go
new file mode 100644
index 0000000..0d0d961
--- /dev/null
+++ b/lib/go-util/join_test.go
@@ -0,0 +1,35 @@
+package util
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import "errors"
+import "fmt"
+
+func ExampleJoinErrsSep() {
+	errs := []error{
+		errors.New("test"),
+		errors.New("quest"),
+	}
+
+	fmt.Println(JoinErrsSep(errs, "\n"))
+
+	// Output: test
+	// quest
+}