This is an automated email from the ASF dual-hosted git repository.
ocket8888 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 3039f2f GitHub Actions workflow to validate go.mod, go.sum, and
vendor directory (#5498)
3039f2f is described below
commit 3039f2f8613febfe8f7c2c30b2e6b5f5a749393a
Author: Zach Hoffman <[email protected]>
AuthorDate: Thu Feb 4 13:34:21 2021 -0700
GitHub Actions workflow to validate go.mod, go.sum, and vendor directory
(#5498)
* Add go.mod/go.sum to Dockerfiles that vendor dependencies
* Fetch dependencies using `go mod vendor`
* Indent using tabs
* Include Traffic Ops API v4 client and tests
* Use indirect expansion for unset environment variable checks
* GitHub Actions workflow to validate go.mod, go.sum, and vendor directory
* Remove unused dependency github.com/kelseyhightower
* Update go.sum using `go mod tidy`
* Use versioned client and do not copy client symlink
* Reduce precompiling API tests to a single cache layer
* Reduce COPY --from= to a single cache layer
* Use API v4 Server struct
---
.github/actions/check-go-modules/README.md | 36 +
.github/actions/check-go-modules/entrypoint.sh | 108 +++
.github/actions/tp-e2e-tests/entrypoint.sh | 8 -
.github/workflows/check-go-modules.yml | 60 ++
build/functions.sh | 2 +
go.sum | 10 +-
infrastructure/cdn-in-a-box/enroller/Dockerfile | 2 +-
infrastructure/cdn-in-a-box/enroller/enroller.go | 6 +-
infrastructure/cdn-in-a-box/traffic_monitor/run.sh | 2 +-
infrastructure/cdn-in-a-box/traffic_ops/config.sh | 2 +-
infrastructure/cdn-in-a-box/traffic_ops/run-go.sh | 2 +-
infrastructure/cdn-in-a-box/traffic_ops/run.sh | 2 +-
.../traffic_ops_integration_test/Dockerfile | 16 +-
.../traffic_ops_integration_test/run.sh | 28 +-
.../traffic_portal_integration_test/run.sh | 2 +-
infrastructure/cdn-in-a-box/traffic_stats/run.sh | 2 +-
traffic_monitor/tests/Dockerfile-golangtest | 1 +
traffic_ops/app/bin/tests/Dockerfile-golangtest | 1 +
traffic_ops/testing/api/v3/cookie_test.go | 2 +-
traffic_ops/testing/api/v3/loginfail_test.go | 2 +-
traffic_ops/testing/api/v3/origins_test.go | 2 +-
.../testing/api/v3/readonlycannotmodify_test.go | 2 +-
traffic_ops/testing/api/v3/steeringtargets_test.go | 2 +-
traffic_ops/testing/api/v3/tenants_test.go | 2 +-
traffic_ops/testing/api/v3/user_test.go | 2 +-
traffic_ops/testing/api/v4/cookie_test.go | 2 +-
traffic_ops/testing/api/v4/loginfail_test.go | 2 +-
traffic_ops/testing/api/v4/origins_test.go | 2 +-
.../testing/api/v4/readonlycannotmodify_test.go | 2 +-
traffic_ops/testing/api/v4/steeringtargets_test.go | 2 +-
traffic_ops/testing/api/v4/tenants_test.go | 2 +-
traffic_ops/testing/api/v4/user_test.go | 2 +-
traffic_ops_ort/testing/docker/ort_test/run.sh | 3 +-
.../envconfig/envconfig_1.8_test.go | 68 --
.../kelseyhightower/envconfig/envconfig_test.go | 804 ---------------------
.../kelseyhightower/envconfig/testdata/custom.txt | 33 -
.../envconfig/testdata/default_list.txt | 168 -----
.../envconfig/testdata/default_table.txt | 37 -
.../kelseyhightower/envconfig/testdata/fault.txt | 33 -
.../kelseyhightower/envconfig/usage_test.go | 155 ----
40 files changed, 262 insertions(+), 1357 deletions(-)
diff --git a/.github/actions/check-go-modules/README.md
b/.github/actions/check-go-modules/README.md
new file mode 100644
index 0000000..4cd4557
--- /dev/null
+++ b/.github/actions/check-go-modules/README.md
@@ -0,0 +1,36 @@
+<!--
+ 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.
+-->
+# check-go-modules action
+
+This action lets you perform checks to verify that
+- `go.mod` is unmodified after installing modules
+- `go.sum` is unmodified after installing modules
+- After installing modules, the `vendor` directory contains no untracked
files, modified files, or deleted files.
+
+## Outputs
+### `exit-code`
+
+Exit code is 0 if the check succeeded.
+
+## Example usage
+```yaml
+- run: .github/actions/check-go-modules/entrypoint.sh vendor_dependencies
+- run: .github/actions/check-go-modules/entrypoint.sh check_vendored_deps
+- run: .github/actions/check-go-modules/entrypoint.sh check_go_file go.mod
+```
\ No newline at end of file
diff --git a/.github/actions/check-go-modules/entrypoint.sh
b/.github/actions/check-go-modules/entrypoint.sh
new file mode 100755
index 0000000..a1438fc
--- /dev/null
+++ b/.github/actions/check-go-modules/entrypoint.sh
@@ -0,0 +1,108 @@
+#!/bin/bash
+# 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 -o errexit -o nounset
+trap 'echo "Error on line ${LINENO} of ${0}"; exit 1' ERR
+
+readonly red_fg="$(printf '%s%s' $'\x1B' '[31m')"
+readonly green_fg="$(printf '%s%s' $'\x1B' '[32m')"
+readonly normal_fg="$(printf '%s%s' $'\x1B' '[39m')"
+colored_text() {
+ color="$1"
+ sed "s/^/${color}/" | sed "s/$/${normal_fg}/"
+}
+
+download_go() {
+ . build/functions.sh
+ if verify_and_set_go_version; then
+ return
+ fi
+ go_version="$(cat "${GITHUB_WORKSPACE}/GO_VERSION")"
+ wget -O go.tar.gz
"https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz" --no-verbose
+ echo "Extracting Go ${go_version}..."
+ <<-'SUDO_COMMANDS' sudo sh
+ set -o errexit
+ go_dir="$(command -v go | xargs realpath | xargs dirname | xargs dirname)"
+ mv "$go_dir" "${go_dir}.unused"
+ tar -C /usr/local -xzf go.tar.gz
+ SUDO_COMMANDS
+ rm go.tar.gz
+ go version
+}
+
+vendor_dependencies() {
+ go mod tidy
+ go mod vendor
+}
+
+check_vendored_deps() {
+ status_output="$(git status --porcelain -- vendor)"
+ if [[ "$(<<<"$status_output" sed '/^$/d' | wc -l)" -eq 0 ]]; then
+ echo 'No deleted, modified, or untracked vendor files were
found.' | colored_text "$green_fg"
+ return
+ fi
+
+ declare -A porcelain_symbols
+ porcelain_symbols[' D']=deleted
+ porcelain_symbols[' M']=modified
+ porcelain_symbols[??]=untracked
+
+ for symbol in "${!porcelain_symbols[@]}"; do
+ output_of_type="$(<<<"$status_output" grep "^${symbol} " ||
true)"
+ file_count="$(<<<"$output_of_type" sed '/^$/d' | wc -l)"
+ file_type="${porcelain_symbols[$symbol]}"
+ if [[ "$file_count" -eq 0 ]]; then
+ continue
+ fi
+ echo "${file_count} ${file_type} files were found:" |
colored_text "$red_fg"
+ <<<"$output_of_type" sed "s/^${symbol} //"
+ echo
+ done
+ exit_code=1
+}
+
+check_go_file() {
+ go_file="$1"
+ if git diff --exit-code --no-patch -- "$go_file"; then
+ echo "${go_file} is up-to-date." | colored_text "$green_fg"
+ return
+ fi
+ printf "Changes were found in %s! Please commit them and try
again.\n\n" "$go_file" | colored_text "$red_fg"
+ exit_code=1
+}
+
+GOROOT=/usr/local/go
+export PATH="${PATH}:${GOROOT}/bin"
+export GOPATH="${HOME}/go"
+
+exit_code=0
+declare -A command_exists
+command_exists[download_go]=1
+command_exists[vendor_dependencies]=1
+command_exists[check_vendored_deps]=1
+command_exists[check_go_file]=1
+requested_command="$1"
+shift
+if : "${command_exists[$requested_command]}"; then
+ "$requested_command" "$@"
+else
+ printf '`%s` is not a valid command.\n' "${requested_command}"
+ exit_code=1
+fi
+
+exit $exit_code
diff --git a/.github/actions/tp-e2e-tests/entrypoint.sh
b/.github/actions/tp-e2e-tests/entrypoint.sh
index f306115..6f1b322 100755
--- a/.github/actions/tp-e2e-tests/entrypoint.sh
+++ b/.github/actions/tp-e2e-tests/entrypoint.sh
@@ -165,14 +165,6 @@ if [[ ! -e "$REPO_DIR" ]]; then
fi
cd "${REPO_DIR}/traffic_ops/traffic_ops_golang"
-/usr/local/go/bin/go get -v golang.org/x/net/publicsuffix\
- golang.org/x/crypto/ed25519 \
- golang.org/x/crypto/scrypt \
- golang.org/x/net/idna \
- golang.org/x/net/ipv4 \
- golang.org/x/net/ipv6 \
- golang.org/x/sys/unix \
- golang.org/x/text/secure/bidirule > /dev/null
/usr/local/go/bin/go mod vendor -v > /dev/null
/usr/local/go/bin/go build . > /dev/null
diff --git a/.github/workflows/check-go-modules.yml
b/.github/workflows/check-go-modules.yml
new file mode 100644
index 0000000..8b21b79
--- /dev/null
+++ b/.github/workflows/check-go-modules.yml
@@ -0,0 +1,60 @@
+# 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: Check Go modules
+
+on:
+ push:
+ paths:
+ - .github/check-go-modules/**
+ - .github/workflows/check-go-modules.yml
+ - go.mod
+ - go.sum
+ - GO_VERSION
+ - vendor/**
+ create:
+ pull_request:
+ paths:
+ - .github/check-go-modules/**
+ - .github/workflows/check-go-modules.yml
+ - go.mod
+ - go.sum
+ - GO_VERSION
+ - vendor/**
+ types: [opened, reopened, ready_for_review, synchronize]
+
+jobs:
+ check-go-modules:
+ if: github.event.pull_request.draft == false
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@master
+ - name: Download Go
+ run: .github/actions/check-go-modules/entrypoint.sh download_go
+ - name: Vendor dependencies
+ id: vendor-dependencies
+ run: .github/actions/check-go-modules/entrypoint.sh vendor_dependencies
+ - name: Untracked changes to vendored dependencies
+ if: ${{ steps.vendor-dependencies.outcome == 'success' && always() }}
+ run: .github/actions/check-go-modules/entrypoint.sh check_vendored_deps
+ - name: Changes to go.mod
+ if: ${{ steps.vendor-dependencies.outcome == 'success' && always() }}
+ run: .github/actions/check-go-modules/entrypoint.sh check_go_file
go.mod
+ - name: Changes to go.sum
+ if: ${{ steps.vendor-dependencies.outcome == 'success' && always() }}
+ run: .github/actions/check-go-modules/entrypoint.sh check_go_file
go.sum
diff --git a/build/functions.sh b/build/functions.sh
index 3f49a75..b66ba79 100755
--- a/build/functions.sh
+++ b/build/functions.sh
@@ -309,6 +309,8 @@ createDocsTarball() {
verify_and_set_go_version() {
if [ -v GO_VERSION ]; then
GO_VERSION="$(getGoVersion .)"
+ else
+ GO_VERSION=''
fi
local major_version="$(echo "$GO_VERSION" | awk -F. '{print $1}')"
local minor_version="$(echo "$GO_VERSION" | awk -F. '{print $2}')"
diff --git a/go.sum b/go.sum
index 9677175..95b356a 100644
--- a/go.sum
+++ b/go.sum
@@ -12,6 +12,7 @@ github.com/cenkalti/backoff v2.2.1+incompatible
h1:tNowT99t7UNflLxfYYSlKYsBpXdEe
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod
h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cihub/seelog v0.0.0-20170110094445-7bfb7937d106
h1:R8zmZtokN18E+ZxOar+w+3mOunajBUV15IUjMUXmLtc=
github.com/cihub/seelog v0.0.0-20170110094445-7bfb7937d106/go.mod
h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo=
+github.com/davecgh/go-spew v1.1.0
h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod
h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/siphash v1.1.0
h1:1Rs9eTUlZLPBEvV+2sTaM8O0NWn0ppbgqS7p11aWawI=
github.com/dchest/siphash v1.1.0/go.mod
h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
@@ -24,6 +25,7 @@ github.com/go-acme/lego v2.7.2+incompatible
h1:ThhpPBgf6oa9X/vRd0kEmWOsX7+vmYdck
github.com/go-acme/lego v2.7.2+incompatible/go.mod
h1:yzMNe9CasVUhkquNvti5nAtPmG94USbYxYrZfTkIn0M=
github.com/go-ozzo/ozzo-validation
v3.0.3-0.20180119232150-44af65fe9adf+incompatible
h1:Ew5aKU1f03D3fhlr9oUycwEwAu+/Z6HWVcyuU9vXZjM=
github.com/go-ozzo/ozzo-validation
v3.0.3-0.20180119232150-44af65fe9adf+incompatible/go.mod
h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
+github.com/go-sql-driver/mysql v1.5.0
h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod
h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/gofrs/flock v0.7.2-0.20190320160742-5135e617513b
h1:3QNh5Xo2pmr2nZXENtnztfpjej8XY8EPmvYxF5SzY9M=
github.com/gofrs/flock v0.7.2-0.20190320160742-5135e617513b/go.mod
h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
@@ -43,8 +45,6 @@ github.com/json-iterator/go
v1.1.6-0.20181024152841-05d041de1043 h1:XWlFVbIXnWhO
github.com/json-iterator/go v1.1.6-0.20181024152841-05d041de1043/go.mod
h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/kelseyhightower/envconfig v1.3.1-0.20180308190516-b2c5c876e265
h1:LlnLZiXiFBkEqo80pOI1gVpkSvGI4SgRRWa8OfIGbz0=
github.com/kelseyhightower/envconfig
v1.3.1-0.20180308190516-b2c5c876e265/go.mod
h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
-github.com/kylelemons/godebug v1.1.0
h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
-github.com/kylelemons/godebug v1.1.0/go.mod
h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/kylelemons/godebug v1.1.1-0.20201107061927-e693023230a4
h1:EFGhiCtMc7FHoE+En2UPh3HgvGzWZ0enFfBuu6FtFww=
github.com/kylelemons/godebug v1.1.1-0.20201107061927-e693023230a4/go.mod
h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lestrrat-go/jwx v0.9.1-0.20190702045520-e35178ac2b1f
h1:mcrFGmpYKjQ8uOye+kWChqy5u+PcXngNAKphYoEIUEM=
@@ -53,6 +53,7 @@ github.com/lestrrat/go-jwx v0.0.0-20171104074836-2857e17763b6
h1:Cs+QtIlpsE/GOhC
github.com/lestrrat/go-jwx v0.0.0-20171104074836-2857e17763b6/go.mod
h1:T+yHdCP6MJKtzoVQMHvVCeam5VFwX1+rWzn5zZgKYMI=
github.com/lib/pq v0.0.0-20170707053602-dd1fe2071026
h1:cibC8wCcGwIOBbP8ney1adouY90dheGj861mBFAuMQk=
github.com/lib/pq v0.0.0-20170707053602-dd1fe2071026/go.mod
h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
+github.com/mattn/go-sqlite3 v1.14.5
h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
github.com/mattn/go-sqlite3 v1.14.5/go.mod
h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
github.com/miekg/dns v1.0.6-0.20180406150955-01d59357d468
h1:ABwS8bIszuZkM3o4nP3Hw3rz9TGkMW9lV4Ifp1hMEaI=
github.com/miekg/dns v1.0.6-0.20180406150955-01d59357d468/go.mod
h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
@@ -76,8 +77,10 @@ github.com/pborman/getopt/v2
v2.0.0-20200816005738-fd0d075bf4de h1:i3rei6KlOqwCd
github.com/pborman/getopt/v2 v2.0.0-20200816005738-fd0d075bf4de/go.mod
h1:4NtW75ny4eBw9fO1bhtNdYTlZKYX5/tBLtsOpwKIKd0=
github.com/pkg/errors v0.8.2-0.20190227000051-27936f6d90f9
h1:PCj9X21C4pet4sEcElTfAi6LSl5ShkjE8doieLc+cbU=
github.com/pkg/errors v0.8.2-0.20190227000051-27936f6d90f9/go.mod
h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0
h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod
h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod
h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1
h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod
h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
@@ -91,6 +94,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod
h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod
h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod
h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -116,6 +120,7 @@ gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0
h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdr
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod
h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225
h1:JBwmEvLfCqgPcIq8MjVMQxsF3LVL4XG/HH0qiG0+IFY=
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225/go.mod
h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod
h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod
h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ldap.v2 v2.5.1 h1:wiu0okdNfjlBzg6UWvd1Hn8Y+Ux17/u/4nlk4CQr6tU=
@@ -127,4 +132,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod
h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod
h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/infrastructure/cdn-in-a-box/enroller/Dockerfile
b/infrastructure/cdn-in-a-box/enroller/Dockerfile
index c2c7411..f80e7da 100644
--- a/infrastructure/cdn-in-a-box/enroller/Dockerfile
+++ b/infrastructure/cdn-in-a-box/enroller/Dockerfile
@@ -36,7 +36,7 @@ ENV GOPATH=/go
COPY ./lib/ /go/src/github.com/apache/trafficcontrol/lib/
COPY ./go.mod ./go.sum /go/src/github.com/apache/trafficcontrol/
COPY ./vendor/ /go/src/github.com/apache/trafficcontrol/vendor/
-COPY ./traffic_ops/client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/client/
+COPY ./traffic_ops/v4-client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/v4-client/
COPY ./infrastructure/cdn-in-a-box/
/go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/
WORKDIR
/go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/enroller
diff --git a/infrastructure/cdn-in-a-box/enroller/enroller.go
b/infrastructure/cdn-in-a-box/enroller/enroller.go
index 642694c..5a17050 100644
--- a/infrastructure/cdn-in-a-box/enroller/enroller.go
+++ b/infrastructure/cdn-in-a-box/enroller/enroller.go
@@ -33,7 +33,7 @@ import (
log "github.com/apache/trafficcontrol/lib/go-log"
tc "github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/traffic_ops/client"
+ "github.com/apache/trafficcontrol/traffic_ops/v4-client"
"github.com/fsnotify/fsnotify"
"github.com/kelseyhightower/envconfig"
)
@@ -670,14 +670,14 @@ func enrollProfile(toSession *session, r io.Reader) error
{
// enrollServer takes a json file and creates a Server object using the TO API
func enrollServer(toSession *session, r io.Reader) error {
dec := json.NewDecoder(r)
- var s tc.ServerV30
+ var s tc.ServerV40
err := dec.Decode(&s)
if err != nil {
log.Infof("error decoding Server: %s\n", err)
return err
}
- alerts, _, err := toSession.CreateServerWithHdr(s, nil)
+ alerts, _, err := toSession.CreateServer(s, nil)
if err != nil {
log.Infof("error creating Server: %s\n", err)
return err
diff --git a/infrastructure/cdn-in-a-box/traffic_monitor/run.sh
b/infrastructure/cdn-in-a-box/traffic_monitor/run.sh
index 8f0abd9..c10282b 100755
--- a/infrastructure/cdn-in-a-box/traffic_monitor/run.sh
+++ b/infrastructure/cdn-in-a-box/traffic_monitor/run.sh
@@ -35,7 +35,7 @@ set -m
envvars=( TO_HOST TO_PORT TM_PORT TM_USER TM_PASSWORD)
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
set-dns.sh
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/config.sh
b/infrastructure/cdn-in-a-box/traffic_ops/config.sh
index de6830e..9dc3f6c 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/config.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/config.sh
@@ -39,7 +39,7 @@
envvars=( DB_SERVER DB_PORT DB_ROOT_PASS DB_USER DB_USER_PASS ADMIN_USER
ADMIN_PASS DOMAIN TO_PERL_HOST TO_PERL_PORT TO_PERL_SCHEME TO_HOST TO_PORT
TP_HOST)
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
until [[ -f "$X509_CA_ENV_FILE" ]]
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
index 7a200d6..aa02d88 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
@@ -41,7 +41,7 @@ set -o errexit -o monitor -o nounset -o pipefail -o xtrace;
envvars=( DB_SERVER DB_PORT DB_ROOT_PASS DB_USER DB_USER_PASS ADMIN_USER
ADMIN_PASS)
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
set-dns.sh
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/run.sh
b/infrastructure/cdn-in-a-box/traffic_ops/run.sh
index d61daeb..bb6fc73 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/run.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run.sh
@@ -36,7 +36,7 @@
envvars=( DB_SERVER DB_PORT DB_USER DB_USER_PASS ADMIN_USER ADMIN_PASS
X509_CA_DIR TLD_DOMAIN INFRA_SUBDOMAIN CDN_SUBDOMAIN DS_HOSTS)
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
set-dns.sh
diff --git
a/infrastructure/cdn-in-a-box/traffic_ops_integration_test/Dockerfile
b/infrastructure/cdn-in-a-box/traffic_ops_integration_test/Dockerfile
index 8309496..954ca74 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops_integration_test/Dockerfile
+++ b/infrastructure/cdn-in-a-box/traffic_ops_integration_test/Dockerfile
@@ -47,7 +47,7 @@ COPY ./lib/ /go/src/github.com/apache/trafficcontrol/lib/
COPY ./traffic_ops/v1-client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/v1-client/
COPY ./traffic_ops/v2-client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/v2-client/
COPY ./traffic_ops/v3-client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/v3-client/
-COPY ./traffic_ops/client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/client/
+COPY ./traffic_ops/v4-client/
/go/src/github.com/apache/trafficcontrol/traffic_ops/v4-client/
COPY ./traffic_ops/testing/api
/go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api
COPY ./traffic_ops/traffic_ops_golang
/go/src/github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang
@@ -56,9 +56,11 @@ COPY ./go.mod ./go.sum
/go/src/github.com/apache/trafficcontrol/
WORKDIR /go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api
RUN go mod vendor -v
-RUN CGO_ENABLED=0 go test -c ./v1* -ldflags="-w -s" -o
traffic_ops_v1_integration_test
-RUN CGO_ENABLED=0 go test -c ./v2* -ldflags="-w -s" -o
traffic_ops_v2_integration_test
-RUN CGO_ENABLED=0 go test -c ./v3* -ldflags="-w -s" -o
traffic_ops_v3_integration_test
+ENV CGO_ENABLED=0
+RUN set -o errexit -o xtrace;\
+ for api_version in v1 v2 v3 v4; do\
+ go test -c ./$api_version -ldflags="-w -s" -o
traffic_ops_${api_version}_integration_test;\
+ done
FROM alpine:3.11
@@ -82,14 +84,12 @@ COPY
./infrastructure/cdn-in-a-box/traffic_ops_integration_test/config.sh /opt/i
COPY ./traffic_ops/testing/api/v1/tc-fixtures.json
/opt/integration/app/tc-fixtures-v1.json
COPY ./traffic_ops/testing/api/v2/tc-fixtures.json
/opt/integration/app/tc-fixtures-v2.json
COPY ./traffic_ops/testing/api/v3/tc-fixtures.json
/opt/integration/app/tc-fixtures-v3.json
+COPY ./traffic_ops/testing/api/v4/tc-fixtures.json
/opt/integration/app/tc-fixtures-v4.json
COPY --from=integration-builder \
/go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api/traffic_ops_v1_integration_test
\
- /opt/integration/app/
-COPY --from=integration-builder \
/go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api/traffic_ops_v2_integration_test
\
- /opt/integration/app/
-COPY --from=integration-builder \
/go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api/traffic_ops_v3_integration_test
\
+
/go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api/traffic_ops_v4_integration_test
\
/opt/integration/app/
COPY --from=integration-builder \
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_integration_test/run.sh
b/infrastructure/cdn-in-a-box/traffic_ops_integration_test/run.sh
index d02d048..a38cd97 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops_integration_test/run.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops_integration_test/run.sh
@@ -21,7 +21,7 @@ envvars=( DB_SERVER DB_PORT DB_ROOT_PASS DB_USER DB_USER_PASS
ADMIN_USER ADMIN_P
set -ex
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
source to-access.sh
@@ -31,28 +31,26 @@ insert-self-into-dns.sh
TO_URL="https://$TO_FQDN:$TO_PORT"
while ! to-ping 2>/dev/null; do
- echo waiting for trafficops
- sleep 3
+ echo waiting for trafficops
+ sleep 3
done
# if [[ -r ]]; then; source config.sh; done traffic_ops/run.sh
# if [[ -x ]]; then;./config.sh; done traffic_ops/run-go.sh
source config.sh
-./traffic_ops_v1_integration_test -test.v -cfg=traffic-ops-test.conf
-fixtures=tc-fixtures-v1.json 2>&1 | ./go-junit-report
--package-name=golang.test.toapi.v1 --set-exit-code >
/junit/golang.test.toapi.v1.xml && find /junit -type 'f' | xargs chmod 664
-export v1=$?
-./traffic_ops_v2_integration_test -test.v -cfg=traffic-ops-test.conf
-fixtures=tc-fixtures-v2.json 2>&1 | ./go-junit-report
--package-name=golang.test.toapi.v2 --set-exit-code >
/junit/golang.test.toapi.v2.xml && find /junit -type 'f' | xargs chmod 664
-export v2=$?
-./traffic_ops_v3_integration_test -test.v -cfg=traffic-ops-test.conf
-fixtures=tc-fixtures-v3.json 2>&1 | ./go-junit-report
--package-name=golang.test.toapi.v3 --set-exit-code >
/junit/golang.test.toapi.v3.xml && find /junit -type 'f' | xargs chmod 664
-export v3=$?
+exit_code=0
+for api_version in v{1..4}; do
+ ./traffic_ops_${api_version}_integration_test -test.v
-cfg=traffic-ops-test.conf -fixtures=tc-fixtures-${api_version}.json 2>&1 |
./go-junit-report --package-name=golang.test.toapi.${api_version}
--set-exit-code > /junit/golang.test.toapi.${api_version}.xml && find /junit
-type 'f' | xargs chmod 664
+ declare ${api_version}_exit_code=$?
+done
-cat /junit/golang.test.toapi.v1.xml /junit/golang.test.toapi.v2.xml
/junit/golang.test.toapi.v3.xml
+cat /junit/golang.test.toapi.v{1..4}.xml
-if [ $v1 -eq 0 ] && [ $v2 -eq 0 ] && [ $v3 -eq 0 ]
-then
- echo "TO API tests success"
+if [[ $v1_exit_code -eq 0 && $v2_exit_code -eq 0 && $v3_exit_code -eq 0 &&
$v4_exit_code -eq 0 ]]; then
+ echo "TO API tests success"
else
- echo "TO API tests failed"
- exit 1
+ echo "TO API tests failed"
+ exit 1
fi
diff --git a/infrastructure/cdn-in-a-box/traffic_portal_integration_test/run.sh
b/infrastructure/cdn-in-a-box/traffic_portal_integration_test/run.sh
index 278cb84..a04bea3 100755
--- a/infrastructure/cdn-in-a-box/traffic_portal_integration_test/run.sh
+++ b/infrastructure/cdn-in-a-box/traffic_portal_integration_test/run.sh
@@ -19,7 +19,7 @@
envvars=( DB_SERVER DB_PORT DB_ROOT_PASS DB_USER DB_USER_PASS ADMIN_USER
ADMIN_PASS)
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
source to-access.sh
diff --git a/infrastructure/cdn-in-a-box/traffic_stats/run.sh
b/infrastructure/cdn-in-a-box/traffic_stats/run.sh
index b115201..c8bfb9a 100755
--- a/infrastructure/cdn-in-a-box/traffic_stats/run.sh
+++ b/infrastructure/cdn-in-a-box/traffic_stats/run.sh
@@ -34,7 +34,7 @@ set -m
envvars=( TO_HOST TO_PORT INFLUXDB_HOST)
for v in $envvars
do
- if [[ -z $$v ]]; then echo "$v is unset"; exit 1; fi
+ if [[ -z "${!v}" ]]; then echo "$v is unset"; exit 1; fi
done
set-dns.sh
diff --git a/traffic_monitor/tests/Dockerfile-golangtest
b/traffic_monitor/tests/Dockerfile-golangtest
index 09340a3..141efa8 100644
--- a/traffic_monitor/tests/Dockerfile-golangtest
+++ b/traffic_monitor/tests/Dockerfile-golangtest
@@ -38,6 +38,7 @@ ARG DIR=github.com/apache/trafficcontrol
ADD traffic_monitor /go/src/$DIR/traffic_monitor
ADD traffic_ops /go/src/$DIR/traffic_ops
ADD lib /go/src/$DIR/lib
+ADD go.mod go.sum /go/src/$DIR/
ADD vendor /go/src/$DIR/vendor
VOLUME ["/junit"]
diff --git a/traffic_ops/app/bin/tests/Dockerfile-golangtest
b/traffic_ops/app/bin/tests/Dockerfile-golangtest
index c12e918..50cfd49 100644
--- a/traffic_ops/app/bin/tests/Dockerfile-golangtest
+++ b/traffic_ops/app/bin/tests/Dockerfile-golangtest
@@ -38,6 +38,7 @@ ENV PATH="${PATH}:${GOPATH}/bin"
ADD traffic_ops /go/src/$DIR/traffic_ops
ADD lib /go/src/$DIR/lib
ADD traffic_monitor /go/src/$DIR/traffic_monitor
+ADD go.mod go.sum /go/src/$DIR/
ADD vendor /go/src/$DIR/vendor
WORKDIR /go/src/$DIR/traffic_ops/traffic_ops_golang
diff --git a/traffic_ops/testing/api/v3/cookie_test.go
b/traffic_ops/testing/api/v3/cookie_test.go
index b3526d4..7bc8f4b 100644
--- a/traffic_ops/testing/api/v3/cookie_test.go
+++ b/traffic_ops/testing/api/v3/cookie_test.go
@@ -22,7 +22,7 @@ import (
"testing"
"github.com/apache/trafficcontrol/lib/go-tc"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
func TestCookies(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/loginfail_test.go
b/traffic_ops/testing/api/v3/loginfail_test.go
index 52ef0a5..d669a42 100644
--- a/traffic_ops/testing/api/v3/loginfail_test.go
+++ b/traffic_ops/testing/api/v3/loginfail_test.go
@@ -24,7 +24,7 @@ import (
"golang.org/x/net/publicsuffix"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
func TestLoginFail(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/origins_test.go
b/traffic_ops/testing/api/v3/origins_test.go
index 2ac240b..efc7b6b 100644
--- a/traffic_ops/testing/api/v3/origins_test.go
+++ b/traffic_ops/testing/api/v3/origins_test.go
@@ -25,7 +25,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
func TestOrigins(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/readonlycannotmodify_test.go
b/traffic_ops/testing/api/v3/readonlycannotmodify_test.go
index fe890a5..e63c93f 100644
--- a/traffic_ops/testing/api/v3/readonlycannotmodify_test.go
+++ b/traffic_ops/testing/api/v3/readonlycannotmodify_test.go
@@ -21,7 +21,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-tc"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
func TestReadOnlyCannotModify(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/steeringtargets_test.go
b/traffic_ops/testing/api/v3/steeringtargets_test.go
index 4871448..e59422d 100644
--- a/traffic_ops/testing/api/v3/steeringtargets_test.go
+++ b/traffic_ops/testing/api/v3/steeringtargets_test.go
@@ -22,7 +22,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-util"
- "github.com/apache/trafficcontrol/traffic_ops/client"
+ "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
var SteeringUserSession *client.Session
diff --git a/traffic_ops/testing/api/v3/tenants_test.go
b/traffic_ops/testing/api/v3/tenants_test.go
index 33b8aab..e0560f6 100644
--- a/traffic_ops/testing/api/v3/tenants_test.go
+++ b/traffic_ops/testing/api/v3/tenants_test.go
@@ -25,7 +25,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/traffic_ops/client"
+ "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
func TestTenants(t *testing.T) {
diff --git a/traffic_ops/testing/api/v3/user_test.go
b/traffic_ops/testing/api/v3/user_test.go
index a1179a3..fc6a0b8 100644
--- a/traffic_ops/testing/api/v3/user_test.go
+++ b/traffic_ops/testing/api/v3/user_test.go
@@ -27,7 +27,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v3-client"
)
func TestUsers(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/cookie_test.go
b/traffic_ops/testing/api/v4/cookie_test.go
index 2e9dfdb..0446d71 100644
--- a/traffic_ops/testing/api/v4/cookie_test.go
+++ b/traffic_ops/testing/api/v4/cookie_test.go
@@ -22,7 +22,7 @@ import (
"testing"
"github.com/apache/trafficcontrol/lib/go-tc"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestCookies(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/loginfail_test.go
b/traffic_ops/testing/api/v4/loginfail_test.go
index 5083fb5..2a5f580 100644
--- a/traffic_ops/testing/api/v4/loginfail_test.go
+++ b/traffic_ops/testing/api/v4/loginfail_test.go
@@ -24,7 +24,7 @@ import (
"golang.org/x/net/publicsuffix"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestLoginFail(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/origins_test.go
b/traffic_ops/testing/api/v4/origins_test.go
index 3f548bd..f5d969b 100644
--- a/traffic_ops/testing/api/v4/origins_test.go
+++ b/traffic_ops/testing/api/v4/origins_test.go
@@ -25,7 +25,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestOrigins(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/readonlycannotmodify_test.go
b/traffic_ops/testing/api/v4/readonlycannotmodify_test.go
index a487455..2d41806 100644
--- a/traffic_ops/testing/api/v4/readonlycannotmodify_test.go
+++ b/traffic_ops/testing/api/v4/readonlycannotmodify_test.go
@@ -21,7 +21,7 @@ import (
"time"
"github.com/apache/trafficcontrol/lib/go-tc"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestReadOnlyCannotModify(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/steeringtargets_test.go
b/traffic_ops/testing/api/v4/steeringtargets_test.go
index 04ebffd..b6b878f 100644
--- a/traffic_ops/testing/api/v4/steeringtargets_test.go
+++ b/traffic_ops/testing/api/v4/steeringtargets_test.go
@@ -22,7 +22,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-util"
- "github.com/apache/trafficcontrol/traffic_ops/client"
+ "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
var SteeringUserSession *client.Session
diff --git a/traffic_ops/testing/api/v4/tenants_test.go
b/traffic_ops/testing/api/v4/tenants_test.go
index 311c06d..c653252 100644
--- a/traffic_ops/testing/api/v4/tenants_test.go
+++ b/traffic_ops/testing/api/v4/tenants_test.go
@@ -25,7 +25,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
- "github.com/apache/trafficcontrol/traffic_ops/client"
+ "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestTenants(t *testing.T) {
diff --git a/traffic_ops/testing/api/v4/user_test.go
b/traffic_ops/testing/api/v4/user_test.go
index 902dfc9..28ccf37 100644
--- a/traffic_ops/testing/api/v4/user_test.go
+++ b/traffic_ops/testing/api/v4/user_test.go
@@ -27,7 +27,7 @@ import (
"github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
- toclient "github.com/apache/trafficcontrol/traffic_ops/client"
+ toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)
func TestUsers(t *testing.T) {
diff --git a/traffic_ops_ort/testing/docker/ort_test/run.sh
b/traffic_ops_ort/testing/docker/ort_test/run.sh
index a87065d..13540e1 100755
--- a/traffic_ops_ort/testing/docker/ort_test/run.sh
+++ b/traffic_ops_ort/testing/docker/ort_test/run.sh
@@ -59,8 +59,7 @@ else
fi
# fetch dependent packages for tests
-go get golang.org/x/crypto/scrypt
-go get golang.org/x/net/publicsuffix
+go mod vendor -v
if [ -f /systemctl.sh ]; then
mv /bin/systemctl /bin/systemctl.save
diff --git a/vendor/github.com/kelseyhightower/envconfig/envconfig_1.8_test.go
b/vendor/github.com/kelseyhightower/envconfig/envconfig_1.8_test.go
deleted file mode 100644
index 0b0d401..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/envconfig_1.8_test.go
+++ /dev/null
@@ -1,68 +0,0 @@
-// +build go1.8
-
-package envconfig
-
-import (
- "os"
- "net/url"
- "testing"
- "errors"
-)
-
-type SpecWithURL struct {
- UrlValue url.URL
- UrlPointer *url.URL
-}
-
-func TestParseURL(t *testing.T) {
- var s SpecWithURL
-
- os.Clearenv()
- os.Setenv("ENV_CONFIG_URLVALUE",
"https://github.com/kelseyhightower/envconfig")
- os.Setenv("ENV_CONFIG_URLPOINTER",
"https://github.com/kelseyhightower/envconfig")
-
- err := Process("env_config", &s)
- if err != nil {
- t.Fatal("unexpected error:", err)
- }
-
- u, err := url.Parse("https://github.com/kelseyhightower/envconfig")
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
-
- if s.UrlValue != *u {
- t.Errorf("expected %q, got %q", u, s.UrlValue.String())
- }
-
- if *s.UrlPointer != *u {
- t.Errorf("expected %q, got %q", u, s.UrlPointer)
- }
-}
-
-func TestParseURLError(t *testing.T) {
- var s SpecWithURL
-
- os.Clearenv()
- os.Setenv("ENV_CONFIG_URLPOINTER", "http_://foo")
-
- err := Process("env_config", &s)
-
- v, ok := err.(*ParseError)
- if !ok {
- t.Fatalf("expected ParseError, got %T %v", err, err)
- }
- if v.FieldName != "UrlPointer" {
- t.Errorf("expected %s, got %v", "UrlPointer", v.FieldName)
- }
-
- expectedUnerlyingError := url.Error{
- Op: "parse",
- URL: "http_://foo",
- Err: errors.New("first path segment in URL cannot contain
colon"),
- }
-
- if v.Err.Error() != expectedUnerlyingError.Error() {
- t.Errorf("expected %q, got %q", expectedUnerlyingError, v.Err)
- }
-}
diff --git a/vendor/github.com/kelseyhightower/envconfig/envconfig_test.go
b/vendor/github.com/kelseyhightower/envconfig/envconfig_test.go
deleted file mode 100644
index bcea73c..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/envconfig_test.go
+++ /dev/null
@@ -1,804 +0,0 @@
-// Copyright (c) 2013 Kelsey Hightower. All rights reserved.
-// Use of this source code is governed by the MIT License that can be found in
-// the LICENSE file.
-
-package envconfig
-
-import (
- "flag"
- "fmt"
- "os"
- "testing"
- "time"
- "net/url"
-)
-
-type HonorDecodeInStruct struct {
- Value string
-}
-
-func (h *HonorDecodeInStruct) Decode(env string) error {
- h.Value = "decoded"
- return nil
-}
-
-type CustomURL struct {
- Value *url.URL
-}
-
-func (cu *CustomURL) UnmarshalBinary(data []byte) error {
- u, err := url.Parse(string(data))
- cu.Value = u
- return err
-}
-
-type Specification struct {
- Embedded `desc:"can we document a struct"`
- EmbeddedButIgnored `ignored:"true"`
- Debug bool
- Port int
- Rate float32
- User string
- TTL uint32
- Timeout time.Duration
- AdminUsers []string
- MagicNumbers []int
- ColorCodes map[string]int
- MultiWordVar string
- MultiWordVarWithAutoSplit uint32 `split_words:"true"`
- SomePointer *string
- SomePointerWithDefault *string `default:"foo2baz" desc:"foorbar
is the word"`
- MultiWordVarWithAlt string
`envconfig:"MULTI_WORD_VAR_WITH_ALT" desc:"what alt"`
- MultiWordVarWithLowerCaseAlt string
`envconfig:"multi_word_var_with_lower_case_alt"`
- NoPrefixWithAlt string `envconfig:"SERVICE_HOST"`
- DefaultVar string `default:"foobar"`
- RequiredVar string `required:"True"`
- NoPrefixDefault string `envconfig:"BROKER"
default:"127.0.0.1"`
- RequiredDefault string `required:"true" default:"foo2bar"`
- Ignored string `ignored:"true"`
- NestedSpecification struct {
- Property string `envconfig:"inner"`
- PropertyWithDefault string `default:"fuzzybydefault"`
- } `envconfig:"outer"`
- AfterNested string
- DecodeStruct HonorDecodeInStruct `envconfig:"honor"`
- Datetime time.Time
- MapField map[string]string `default:"one:two,three:four"`
- UrlValue CustomURL
- UrlPointer *CustomURL
-}
-
-type Embedded struct {
- Enabled bool `desc:"some embedded value"`
- EmbeddedPort int
- MultiWordVar string
- MultiWordVarWithAlt string `envconfig:"MULTI_WITH_DIFFERENT_ALT"`
- EmbeddedAlt string `envconfig:"EMBEDDED_WITH_ALT"`
- EmbeddedIgnored string `ignored:"true"`
-}
-
-type EmbeddedButIgnored struct {
- FirstEmbeddedButIgnored string
- SecondEmbeddedButIgnored string
-}
-
-func TestProcess(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEBUG", "true")
- os.Setenv("ENV_CONFIG_PORT", "8080")
- os.Setenv("ENV_CONFIG_RATE", "0.5")
- os.Setenv("ENV_CONFIG_USER", "Kelsey")
- os.Setenv("ENV_CONFIG_TIMEOUT", "2m")
- os.Setenv("ENV_CONFIG_ADMINUSERS", "John,Adam,Will")
- os.Setenv("ENV_CONFIG_MAGICNUMBERS", "5,10,20")
- os.Setenv("ENV_CONFIG_COLORCODES", "red:1,green:2,blue:3")
- os.Setenv("SERVICE_HOST", "127.0.0.1")
- os.Setenv("ENV_CONFIG_TTL", "30")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- os.Setenv("ENV_CONFIG_IGNORED", "was-not-ignored")
- os.Setenv("ENV_CONFIG_OUTER_INNER", "iamnested")
- os.Setenv("ENV_CONFIG_AFTERNESTED", "after")
- os.Setenv("ENV_CONFIG_HONOR", "honor")
- os.Setenv("ENV_CONFIG_DATETIME", "2016-08-16T18:57:05Z")
- os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_AUTO_SPLIT", "24")
- os.Setenv("ENV_CONFIG_URLVALUE",
"https://github.com/kelseyhightower/envconfig")
- os.Setenv("ENV_CONFIG_URLPOINTER",
"https://github.com/kelseyhightower/envconfig")
- err := Process("env_config", &s)
- if err != nil {
- t.Error(err.Error())
- }
- if s.NoPrefixWithAlt != "127.0.0.1" {
- t.Errorf("expected %v, got %v", "127.0.0.1", s.NoPrefixWithAlt)
- }
- if !s.Debug {
- t.Errorf("expected %v, got %v", true, s.Debug)
- }
- if s.Port != 8080 {
- t.Errorf("expected %d, got %v", 8080, s.Port)
- }
- if s.Rate != 0.5 {
- t.Errorf("expected %f, got %v", 0.5, s.Rate)
- }
- if s.TTL != 30 {
- t.Errorf("expected %d, got %v", 30, s.TTL)
- }
- if s.User != "Kelsey" {
- t.Errorf("expected %s, got %s", "Kelsey", s.User)
- }
- if s.Timeout != 2*time.Minute {
- t.Errorf("expected %s, got %s", 2*time.Minute, s.Timeout)
- }
- if s.RequiredVar != "foo" {
- t.Errorf("expected %s, got %s", "foo", s.RequiredVar)
- }
- if len(s.AdminUsers) != 3 ||
- s.AdminUsers[0] != "John" ||
- s.AdminUsers[1] != "Adam" ||
- s.AdminUsers[2] != "Will" {
- t.Errorf("expected %#v, got %#v", []string{"John", "Adam",
"Will"}, s.AdminUsers)
- }
- if len(s.MagicNumbers) != 3 ||
- s.MagicNumbers[0] != 5 ||
- s.MagicNumbers[1] != 10 ||
- s.MagicNumbers[2] != 20 {
- t.Errorf("expected %#v, got %#v", []int{5, 10, 20},
s.MagicNumbers)
- }
- if s.Ignored != "" {
- t.Errorf("expected empty string, got %#v", s.Ignored)
- }
-
- if len(s.ColorCodes) != 3 ||
- s.ColorCodes["red"] != 1 ||
- s.ColorCodes["green"] != 2 ||
- s.ColorCodes["blue"] != 3 {
- t.Errorf(
- "expected %#v, got %#v",
- map[string]int{
- "red": 1,
- "green": 2,
- "blue": 3,
- },
- s.ColorCodes,
- )
- }
-
- if s.NestedSpecification.Property != "iamnested" {
- t.Errorf("expected '%s' string, got %#v", "iamnested",
s.NestedSpecification.Property)
- }
-
- if s.NestedSpecification.PropertyWithDefault != "fuzzybydefault" {
- t.Errorf("expected default '%s' string, got %#v",
"fuzzybydefault", s.NestedSpecification.PropertyWithDefault)
- }
-
- if s.AfterNested != "after" {
- t.Errorf("expected default '%s' string, got %#v", "after",
s.AfterNested)
- }
-
- if s.DecodeStruct.Value != "decoded" {
- t.Errorf("expected default '%s' string, got %#v", "decoded",
s.DecodeStruct.Value)
- }
-
- if expected := time.Date(2016, 8, 16, 18, 57, 05, 0, time.UTC);
!s.Datetime.Equal(expected) {
- t.Errorf("expected %s, got %s", expected.Format(time.RFC3339),
s.Datetime.Format(time.RFC3339))
- }
-
- if s.MultiWordVarWithAutoSplit != 24 {
- t.Errorf("expected %q, got %q", 24, s.MultiWordVarWithAutoSplit)
- }
-
- u, err := url.Parse("https://github.com/kelseyhightower/envconfig")
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
-
- if *s.UrlValue.Value != *u {
- t.Errorf("expected %q, got %q", u, s.UrlValue.Value.String())
- }
-
- if *s.UrlPointer.Value != *u {
- t.Errorf("expected %q, got %q", u, s.UrlPointer.Value.String())
- }
-}
-
-func TestParseErrorBool(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEBUG", "string")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- err := Process("env_config", &s)
- v, ok := err.(*ParseError)
- if !ok {
- t.Errorf("expected ParseError, got %v", v)
- }
- if v.FieldName != "Debug" {
- t.Errorf("expected %s, got %v", "Debug", v.FieldName)
- }
- if s.Debug != false {
- t.Errorf("expected %v, got %v", false, s.Debug)
- }
-}
-
-func TestParseErrorFloat32(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_RATE", "string")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- err := Process("env_config", &s)
- v, ok := err.(*ParseError)
- if !ok {
- t.Errorf("expected ParseError, got %v", v)
- }
- if v.FieldName != "Rate" {
- t.Errorf("expected %s, got %v", "Rate", v.FieldName)
- }
- if s.Rate != 0 {
- t.Errorf("expected %v, got %v", 0, s.Rate)
- }
-}
-
-func TestParseErrorInt(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_PORT", "string")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- err := Process("env_config", &s)
- v, ok := err.(*ParseError)
- if !ok {
- t.Errorf("expected ParseError, got %v", v)
- }
- if v.FieldName != "Port" {
- t.Errorf("expected %s, got %v", "Port", v.FieldName)
- }
- if s.Port != 0 {
- t.Errorf("expected %v, got %v", 0, s.Port)
- }
-}
-
-func TestParseErrorUint(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_TTL", "-30")
- err := Process("env_config", &s)
- v, ok := err.(*ParseError)
- if !ok {
- t.Errorf("expected ParseError, got %v", v)
- }
- if v.FieldName != "TTL" {
- t.Errorf("expected %s, got %v", "TTL", v.FieldName)
- }
- if s.TTL != 0 {
- t.Errorf("expected %v, got %v", 0, s.TTL)
- }
-}
-
-func TestParseErrorSplitWords(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_AUTO_SPLIT", "shakespeare")
- err := Process("env_config", &s)
- v, ok := err.(*ParseError)
- if !ok {
- t.Errorf("expected ParseError, got %v", v)
- }
- if v.FieldName != "MultiWordVarWithAutoSplit" {
- t.Errorf("expected %s, got %v", "", v.FieldName)
- }
- if s.MultiWordVarWithAutoSplit != 0 {
- t.Errorf("expected %v, got %v", 0, s.MultiWordVarWithAutoSplit)
- }
-}
-
-func TestErrInvalidSpecification(t *testing.T) {
- m := make(map[string]string)
- err := Process("env_config", &m)
- if err != ErrInvalidSpecification {
- t.Errorf("expected %v, got %v", ErrInvalidSpecification, err)
- }
-}
-
-func TestUnsetVars(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("USER", "foo")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- // If the var is not defined the non-prefixed version should not be used
- // unless the struct tag says so
- if s.User != "" {
- t.Errorf("expected %q, got %q", "", s.User)
- }
-}
-
-func TestAlternateVarNames(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_MULTI_WORD_VAR", "foo")
- os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_ALT", "bar")
- os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_LOWER_CASE_ALT", "baz")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- // Setting the alt version of the var in the environment has no effect
if
- // the struct tag is not supplied
- if s.MultiWordVar != "" {
- t.Errorf("expected %q, got %q", "", s.MultiWordVar)
- }
-
- // Setting the alt version of the var in the environment correctly sets
- // the value if the struct tag IS supplied
- if s.MultiWordVarWithAlt != "bar" {
- t.Errorf("expected %q, got %q", "bar", s.MultiWordVarWithAlt)
- }
-
- // Alt value is not case sensitive and is treated as all uppercase
- if s.MultiWordVarWithLowerCaseAlt != "baz" {
- t.Errorf("expected %q, got %q", "baz",
s.MultiWordVarWithLowerCaseAlt)
- }
-}
-
-func TestRequiredVar(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foobar")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.RequiredVar != "foobar" {
- t.Errorf("expected %s, got %s", "foobar", s.RequiredVar)
- }
-}
-
-func TestRequiredMissing(t *testing.T) {
- var s Specification
- os.Clearenv()
-
- err := Process("env_config", &s)
- if err == nil {
- t.Error("no failure when missing required variable")
- }
-}
-
-func TestBlankDefaultVar(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "requiredvalue")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.DefaultVar != "foobar" {
- t.Errorf("expected %s, got %s", "foobar", s.DefaultVar)
- }
-
- if *s.SomePointerWithDefault != "foo2baz" {
- t.Errorf("expected %s, got %s", "foo2baz",
*s.SomePointerWithDefault)
- }
-}
-
-func TestNonBlankDefaultVar(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEFAULTVAR", "nondefaultval")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "requiredvalue")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.DefaultVar != "nondefaultval" {
- t.Errorf("expected %s, got %s", "nondefaultval", s.DefaultVar)
- }
-}
-
-func TestExplicitBlankDefaultVar(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEFAULTVAR", "")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "")
-
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.DefaultVar != "" {
- t.Errorf("expected %s, got %s", "\"\"", s.DefaultVar)
- }
-}
-
-func TestAlternateNameDefaultVar(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("BROKER", "betterbroker")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.NoPrefixDefault != "betterbroker" {
- t.Errorf("expected %q, got %q", "betterbroker",
s.NoPrefixDefault)
- }
-
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.NoPrefixDefault != "127.0.0.1" {
- t.Errorf("expected %q, got %q", "127.0.0.1", s.NoPrefixDefault)
- }
-}
-
-func TestRequiredDefault(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.RequiredDefault != "foo2bar" {
- t.Errorf("expected %q, got %q", "foo2bar", s.RequiredDefault)
- }
-}
-
-func TestPointerFieldBlank(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.SomePointer != nil {
- t.Errorf("expected <nil>, got %q", *s.SomePointer)
- }
-}
-
-func TestEmptyMapFieldOverride(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- os.Setenv("ENV_CONFIG_MAPFIELD", "")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if s.MapField == nil {
- t.Error("expected empty map, got <nil>")
- }
-
- if len(s.MapField) != 0 {
- t.Errorf("expected empty map, got map of size %d",
len(s.MapField))
- }
-}
-
-func TestMustProcess(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEBUG", "true")
- os.Setenv("ENV_CONFIG_PORT", "8080")
- os.Setenv("ENV_CONFIG_RATE", "0.5")
- os.Setenv("ENV_CONFIG_USER", "Kelsey")
- os.Setenv("SERVICE_HOST", "127.0.0.1")
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- MustProcess("env_config", &s)
-
- defer func() {
- if err := recover(); err != nil {
- return
- }
-
- t.Error("expected panic")
- }()
- m := make(map[string]string)
- MustProcess("env_config", &m)
-}
-
-func TestEmbeddedStruct(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "required")
- os.Setenv("ENV_CONFIG_ENABLED", "true")
- os.Setenv("ENV_CONFIG_EMBEDDEDPORT", "1234")
- os.Setenv("ENV_CONFIG_MULTIWORDVAR", "foo")
- os.Setenv("ENV_CONFIG_MULTI_WORD_VAR_WITH_ALT", "bar")
- os.Setenv("ENV_CONFIG_MULTI_WITH_DIFFERENT_ALT", "baz")
- os.Setenv("ENV_CONFIG_EMBEDDED_WITH_ALT", "foobar")
- os.Setenv("ENV_CONFIG_SOMEPOINTER", "foobaz")
- os.Setenv("ENV_CONFIG_EMBEDDED_IGNORED", "was-not-ignored")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
- if !s.Enabled {
- t.Errorf("expected %v, got %v", true, s.Enabled)
- }
- if s.EmbeddedPort != 1234 {
- t.Errorf("expected %d, got %v", 1234, s.EmbeddedPort)
- }
- if s.MultiWordVar != "foo" {
- t.Errorf("expected %s, got %s", "foo", s.MultiWordVar)
- }
- if s.Embedded.MultiWordVar != "foo" {
- t.Errorf("expected %s, got %s", "foo", s.Embedded.MultiWordVar)
- }
- if s.MultiWordVarWithAlt != "bar" {
- t.Errorf("expected %s, got %s", "bar", s.MultiWordVarWithAlt)
- }
- if s.Embedded.MultiWordVarWithAlt != "baz" {
- t.Errorf("expected %s, got %s", "baz",
s.Embedded.MultiWordVarWithAlt)
- }
- if s.EmbeddedAlt != "foobar" {
- t.Errorf("expected %s, got %s", "foobar", s.EmbeddedAlt)
- }
- if *s.SomePointer != "foobaz" {
- t.Errorf("expected %s, got %s", "foobaz", *s.SomePointer)
- }
- if s.EmbeddedIgnored != "" {
- t.Errorf("expected empty string, got %#v", s.Ignored)
- }
-}
-
-func TestEmbeddedButIgnoredStruct(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "required")
- os.Setenv("ENV_CONFIG_FIRSTEMBEDDEDBUTIGNORED", "was-not-ignored")
- os.Setenv("ENV_CONFIG_SECONDEMBEDDEDBUTIGNORED", "was-not-ignored")
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
- if s.FirstEmbeddedButIgnored != "" {
- t.Errorf("expected empty string, got %#v", s.Ignored)
- }
- if s.SecondEmbeddedButIgnored != "" {
- t.Errorf("expected empty string, got %#v", s.Ignored)
- }
-}
-
-func TestNonPointerFailsProperly(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "snap")
-
- err := Process("env_config", s)
- if err != ErrInvalidSpecification {
- t.Errorf("non-pointer should fail with ErrInvalidSpecification,
was instead %s", err)
- }
-}
-
-func TestCustomValueFields(t *testing.T) {
- var s struct {
- Foo string
- Bar bracketed
- Baz quoted
- Struct setterStruct
- }
-
- // Set would panic when the receiver is nil,
- // so make sure it has an initial value to replace.
- s.Baz = quoted{new(bracketed)}
-
- os.Clearenv()
- os.Setenv("ENV_CONFIG_FOO", "foo")
- os.Setenv("ENV_CONFIG_BAR", "bar")
- os.Setenv("ENV_CONFIG_BAZ", "baz")
- os.Setenv("ENV_CONFIG_STRUCT", "inner")
-
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if want := "foo"; s.Foo != want {
- t.Errorf("foo: got %#q, want %#q", s.Foo, want)
- }
-
- if want := "[bar]"; s.Bar.String() != want {
- t.Errorf("bar: got %#q, want %#q", s.Bar, want)
- }
-
- if want := `["baz"]`; s.Baz.String() != want {
- t.Errorf(`baz: got %#q, want %#q`, s.Baz, want)
- }
-
- if want := `setterstruct{"inner"}`; s.Struct.Inner != want {
- t.Errorf(`Struct.Inner: got %#q, want %#q`, s.Struct.Inner,
want)
- }
-}
-
-func TestCustomPointerFields(t *testing.T) {
- var s struct {
- Foo string
- Bar *bracketed
- Baz *quoted
- Struct *setterStruct
- }
-
- // Set would panic when the receiver is nil,
- // so make sure they have initial values to replace.
- s.Bar = new(bracketed)
- s.Baz = "ed{new(bracketed)}
-
- os.Clearenv()
- os.Setenv("ENV_CONFIG_FOO", "foo")
- os.Setenv("ENV_CONFIG_BAR", "bar")
- os.Setenv("ENV_CONFIG_BAZ", "baz")
- os.Setenv("ENV_CONFIG_STRUCT", "inner")
-
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
-
- if want := "foo"; s.Foo != want {
- t.Errorf("foo: got %#q, want %#q", s.Foo, want)
- }
-
- if want := "[bar]"; s.Bar.String() != want {
- t.Errorf("bar: got %#q, want %#q", s.Bar, want)
- }
-
- if want := `["baz"]`; s.Baz.String() != want {
- t.Errorf(`baz: got %#q, want %#q`, s.Baz, want)
- }
-
- if want := `setterstruct{"inner"}`; s.Struct.Inner != want {
- t.Errorf(`Struct.Inner: got %#q, want %#q`, s.Struct.Inner,
want)
- }
-}
-
-func TestEmptyPrefixUsesFieldNames(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("REQUIREDVAR", "foo")
-
- err := Process("", &s)
- if err != nil {
- t.Errorf("Process failed: %s", err)
- }
-
- if s.RequiredVar != "foo" {
- t.Errorf(
- `RequiredVar not populated correctly: expected "foo",
got %q`,
- s.RequiredVar,
- )
- }
-}
-
-func TestNestedStructVarName(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "required")
- val := "found with only short name"
- os.Setenv("INNER", val)
- if err := Process("env_config", &s); err != nil {
- t.Error(err.Error())
- }
- if s.NestedSpecification.Property != val {
- t.Errorf("expected %s, got %s", val,
s.NestedSpecification.Property)
- }
-}
-
-func TestTextUnmarshalerError(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- os.Setenv("ENV_CONFIG_DATETIME", "I'M NOT A DATE")
-
- err := Process("env_config", &s)
-
- v, ok := err.(*ParseError)
- if !ok {
- t.Errorf("expected ParseError, got %v", v)
- }
- if v.FieldName != "Datetime" {
- t.Errorf("expected %s, got %v", "Datetime", v.FieldName)
- }
-
- expectedLowLevelError := time.ParseError{
- Layout: time.RFC3339,
- Value: "I'M NOT A DATE",
- LayoutElem: "2006",
- ValueElem: "I'M NOT A DATE",
- }
-
- if v.Err.Error() != expectedLowLevelError.Error() {
- t.Errorf("expected %s, got %s", expectedLowLevelError, v.Err)
- }
-}
-
-func TestBinaryUnmarshalerError(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_REQUIREDVAR", "foo")
- os.Setenv("ENV_CONFIG_URLPOINTER", "http://%41:8080/")
-
- err := Process("env_config", &s)
-
- v, ok := err.(*ParseError)
- if !ok {
- t.Fatalf("expected ParseError, got %T %v", err, err)
- }
- if v.FieldName != "UrlPointer" {
- t.Errorf("expected %s, got %v", "UrlPointer", v.FieldName)
- }
-
- // To be compatible with go 1.5 and lower we should do a very basic
check,
- // because underlying error message varies in go 1.5 and go 1.6+.
-
- ue, ok := v.Err.(*url.Error)
- if !ok {
- t.Errorf("expected error type to be \"*url.Error\", got %T",
v.Err)
- }
-
- if ue.Op != "parse" {
- t.Errorf("expected error op to be \"parse\", got %q", ue.Op)
- }
-}
-
-func TestCheckDisallowedOnlyAllowed(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEBUG", "true")
- os.Setenv("UNRELATED_ENV_VAR", "true")
- err := CheckDisallowed("env_config", &s)
- if err != nil {
- t.Errorf("expected no error, got %s", err)
- }
-}
-
-func TestCheckDisallowedMispelled(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEBUG", "true")
- os.Setenv("ENV_CONFIG_ZEBUG", "false")
- err := CheckDisallowed("env_config", &s)
- if experr := "unknown environment variable ENV_CONFIG_ZEBUG";
err.Error() != experr {
- t.Errorf("expected %s, got %s", experr, err)
- }
-}
-
-func TestCheckDisallowedIgnored(t *testing.T) {
- var s Specification
- os.Clearenv()
- os.Setenv("ENV_CONFIG_DEBUG", "true")
- os.Setenv("ENV_CONFIG_IGNORED", "false")
- err := CheckDisallowed("env_config", &s)
- if experr := "unknown environment variable ENV_CONFIG_IGNORED";
err.Error() != experr {
- t.Errorf("expected %s, got %s", experr, err)
- }
-}
-
-type bracketed string
-
-func (b *bracketed) Set(value string) error {
- *b = bracketed("[" + value + "]")
- return nil
-}
-
-func (b bracketed) String() string {
- return string(b)
-}
-
-// quoted is used to test the precedence of Decode over Set.
-// The sole field is a flag.Value rather than a setter to validate that
-// all flag.Value implementations are also Setter implementations.
-type quoted struct{ flag.Value }
-
-func (d quoted) Decode(value string) error {
- return d.Set(`"` + value + `"`)
-}
-
-type setterStruct struct {
- Inner string
-}
-
-func (ss *setterStruct) Set(value string) error {
- ss.Inner = fmt.Sprintf("setterstruct{%q}", value)
- return nil
-}
diff --git a/vendor/github.com/kelseyhightower/envconfig/testdata/custom.txt
b/vendor/github.com/kelseyhightower/envconfig/testdata/custom.txt
deleted file mode 100644
index 67e9fa0..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/testdata/custom.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-ENV_CONFIG_ENABLED=some.embedded.value
-ENV_CONFIG_EMBEDDEDPORT=
-ENV_CONFIG_MULTIWORDVAR=
-ENV_CONFIG_MULTI_WITH_DIFFERENT_ALT=
-ENV_CONFIG_EMBEDDED_WITH_ALT=
-ENV_CONFIG_DEBUG=
-ENV_CONFIG_PORT=
-ENV_CONFIG_RATE=
-ENV_CONFIG_USER=
-ENV_CONFIG_TTL=
-ENV_CONFIG_TIMEOUT=
-ENV_CONFIG_ADMINUSERS=
-ENV_CONFIG_MAGICNUMBERS=
-ENV_CONFIG_COLORCODES=
-ENV_CONFIG_MULTIWORDVAR=
-ENV_CONFIG_MULTI_WORD_VAR_WITH_AUTO_SPLIT=
-ENV_CONFIG_SOMEPOINTER=
-ENV_CONFIG_SOMEPOINTERWITHDEFAULT=foorbar.is.the.word
-ENV_CONFIG_MULTI_WORD_VAR_WITH_ALT=what.alt
-ENV_CONFIG_MULTI_WORD_VAR_WITH_LOWER_CASE_ALT=
-ENV_CONFIG_SERVICE_HOST=
-ENV_CONFIG_DEFAULTVAR=
-ENV_CONFIG_REQUIREDVAR=
-ENV_CONFIG_BROKER=
-ENV_CONFIG_REQUIREDDEFAULT=
-ENV_CONFIG_OUTER_INNER=
-ENV_CONFIG_OUTER_PROPERTYWITHDEFAULT=
-ENV_CONFIG_AFTERNESTED=
-ENV_CONFIG_HONOR=
-ENV_CONFIG_DATETIME=
-ENV_CONFIG_MAPFIELD=
-ENV_CONFIG_URLVALUE=
-ENV_CONFIG_URLPOINTER=
diff --git
a/vendor/github.com/kelseyhightower/envconfig/testdata/default_list.txt
b/vendor/github.com/kelseyhightower/envconfig/testdata/default_list.txt
deleted file mode 100644
index 41f8b54..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/testdata/default_list.txt
+++ /dev/null
@@ -1,168 +0,0 @@
-This.application.is.configured.via.the.environment..The.following.environment
-variables.can.be.used:
-
-ENV_CONFIG_ENABLED
-..[description].some.embedded.value
-..[type]........True.or.False
-..[default].....
-..[required]....
-ENV_CONFIG_EMBEDDEDPORT
-..[description].
-..[type]........Integer
-..[default].....
-..[required]....
-ENV_CONFIG_MULTIWORDVAR
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_MULTI_WITH_DIFFERENT_ALT
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_EMBEDDED_WITH_ALT
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_DEBUG
-..[description].
-..[type]........True.or.False
-..[default].....
-..[required]....
-ENV_CONFIG_PORT
-..[description].
-..[type]........Integer
-..[default].....
-..[required]....
-ENV_CONFIG_RATE
-..[description].
-..[type]........Float
-..[default].....
-..[required]....
-ENV_CONFIG_USER
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_TTL
-..[description].
-..[type]........Unsigned.Integer
-..[default].....
-..[required]....
-ENV_CONFIG_TIMEOUT
-..[description].
-..[type]........Duration
-..[default].....
-..[required]....
-ENV_CONFIG_ADMINUSERS
-..[description].
-..[type]........Comma-separated.list.of.String
-..[default].....
-..[required]....
-ENV_CONFIG_MAGICNUMBERS
-..[description].
-..[type]........Comma-separated.list.of.Integer
-..[default].....
-..[required]....
-ENV_CONFIG_COLORCODES
-..[description].
-..[type]........Comma-separated.list.of.String:Integer.pairs
-..[default].....
-..[required]....
-ENV_CONFIG_MULTIWORDVAR
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_MULTI_WORD_VAR_WITH_AUTO_SPLIT
-..[description].
-..[type]........Unsigned.Integer
-..[default].....
-..[required]....
-ENV_CONFIG_SOMEPOINTER
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_SOMEPOINTERWITHDEFAULT
-..[description].foorbar.is.the.word
-..[type]........String
-..[default].....foo2baz
-..[required]....
-ENV_CONFIG_MULTI_WORD_VAR_WITH_ALT
-..[description].what.alt
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_MULTI_WORD_VAR_WITH_LOWER_CASE_ALT
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_SERVICE_HOST
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_DEFAULTVAR
-..[description].
-..[type]........String
-..[default].....foobar
-..[required]....
-ENV_CONFIG_REQUIREDVAR
-..[description].
-..[type]........String
-..[default].....
-..[required]....true
-ENV_CONFIG_BROKER
-..[description].
-..[type]........String
-..[default].....127.0.0.1
-..[required]....
-ENV_CONFIG_REQUIREDDEFAULT
-..[description].
-..[type]........String
-..[default].....foo2bar
-..[required]....true
-ENV_CONFIG_OUTER_INNER
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_OUTER_PROPERTYWITHDEFAULT
-..[description].
-..[type]........String
-..[default].....fuzzybydefault
-..[required]....
-ENV_CONFIG_AFTERNESTED
-..[description].
-..[type]........String
-..[default].....
-..[required]....
-ENV_CONFIG_HONOR
-..[description].
-..[type]........HonorDecodeInStruct
-..[default].....
-..[required]....
-ENV_CONFIG_DATETIME
-..[description].
-..[type]........Time
-..[default].....
-..[required]....
-ENV_CONFIG_MAPFIELD
-..[description].
-..[type]........Comma-separated.list.of.String:String.pairs
-..[default].....one:two,three:four
-..[required]....
-ENV_CONFIG_URLVALUE
-..[description].
-..[type]........CustomURL
-..[default].....
-..[required]....
-ENV_CONFIG_URLPOINTER
-..[description].
-..[type]........CustomURL
-..[default].....
-..[required]....
diff --git
a/vendor/github.com/kelseyhightower/envconfig/testdata/default_table.txt
b/vendor/github.com/kelseyhightower/envconfig/testdata/default_table.txt
deleted file mode 100644
index f5d918e..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/testdata/default_table.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-This.application.is.configured.via.the.environment..The.following.environment
-variables.can.be.used:
-
-KEY..............................................TYPE............................................DEFAULT...............REQUIRED....DESCRIPTION
-ENV_CONFIG_ENABLED...............................True.or.False.....................................................................some.embedded.value
-ENV_CONFIG_EMBEDDEDPORT..........................Integer...........................................................................
-ENV_CONFIG_MULTIWORDVAR..........................String............................................................................
-ENV_CONFIG_MULTI_WITH_DIFFERENT_ALT..............String............................................................................
-ENV_CONFIG_EMBEDDED_WITH_ALT.....................String............................................................................
-ENV_CONFIG_DEBUG.................................True.or.False.....................................................................
-ENV_CONFIG_PORT..................................Integer...........................................................................
-ENV_CONFIG_RATE..................................Float.............................................................................
-ENV_CONFIG_USER..................................String............................................................................
-ENV_CONFIG_TTL...................................Unsigned.Integer..................................................................
-ENV_CONFIG_TIMEOUT...............................Duration..........................................................................
-ENV_CONFIG_ADMINUSERS............................Comma-separated.list.of.String....................................................
-ENV_CONFIG_MAGICNUMBERS..........................Comma-separated.list.of.Integer...................................................
-ENV_CONFIG_COLORCODES............................Comma-separated.list.of.String:Integer.pairs......................................
-ENV_CONFIG_MULTIWORDVAR..........................String............................................................................
-ENV_CONFIG_MULTI_WORD_VAR_WITH_AUTO_SPLIT........Unsigned.Integer..................................................................
-ENV_CONFIG_SOMEPOINTER...........................String............................................................................
-ENV_CONFIG_SOMEPOINTERWITHDEFAULT................String..........................................foo2baz...........................foorbar.is.the.word
-ENV_CONFIG_MULTI_WORD_VAR_WITH_ALT...............String............................................................................what.alt
-ENV_CONFIG_MULTI_WORD_VAR_WITH_LOWER_CASE_ALT....String............................................................................
-ENV_CONFIG_SERVICE_HOST..........................String............................................................................
-ENV_CONFIG_DEFAULTVAR............................String..........................................foobar............................
-ENV_CONFIG_REQUIREDVAR...........................String................................................................true........
-ENV_CONFIG_BROKER................................String..........................................127.0.0.1.........................
-ENV_CONFIG_REQUIREDDEFAULT.......................String..........................................foo2bar...............true........
-ENV_CONFIG_OUTER_INNER...........................String............................................................................
-ENV_CONFIG_OUTER_PROPERTYWITHDEFAULT.............String..........................................fuzzybydefault....................
-ENV_CONFIG_AFTERNESTED...........................String............................................................................
-ENV_CONFIG_HONOR.................................HonorDecodeInStruct...............................................................
-ENV_CONFIG_DATETIME..............................Time..............................................................................
-ENV_CONFIG_MAPFIELD..............................Comma-separated.list.of.String:String.pairs.....one:two,three:four................
-ENV_CONFIG_URLVALUE..............................CustomURL.........................................................................
-ENV_CONFIG_URLPOINTER............................CustomURL.........................................................................
diff --git a/vendor/github.com/kelseyhightower/envconfig/testdata/fault.txt
b/vendor/github.com/kelseyhightower/envconfig/testdata/fault.txt
deleted file mode 100644
index c75efe5..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/testdata/fault.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
-{.Key}
diff --git a/vendor/github.com/kelseyhightower/envconfig/usage_test.go
b/vendor/github.com/kelseyhightower/envconfig/usage_test.go
deleted file mode 100644
index b433d19..0000000
--- a/vendor/github.com/kelseyhightower/envconfig/usage_test.go
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (c) 2016 Kelsey Hightower and others. All rights reserved.
-// Use of this source code is governed by the MIT License that can be found in
-// the LICENSE file.
-
-package envconfig
-
-import (
- "bytes"
- "io"
- "io/ioutil"
- "log"
- "os"
- "strings"
- "testing"
- "text/tabwriter"
-)
-
-var testUsageTableResult, testUsageListResult, testUsageCustomResult,
testUsageBadFormatResult string
-
-func TestMain(m *testing.M) {
-
- // Load the expected test results from a text file
- data, err := ioutil.ReadFile("testdata/default_table.txt")
- if err != nil {
- log.Fatal(err)
- }
- testUsageTableResult = string(data)
-
- data, err = ioutil.ReadFile("testdata/default_list.txt")
- if err != nil {
- log.Fatal(err)
- }
- testUsageListResult = string(data)
-
- data, err = ioutil.ReadFile("testdata/custom.txt")
- if err != nil {
- log.Fatal(err)
- }
- testUsageCustomResult = string(data)
-
- data, err = ioutil.ReadFile("testdata/fault.txt")
- if err != nil {
- log.Fatal(err)
- }
- testUsageBadFormatResult = string(data)
-
- retCode := m.Run()
- os.Exit(retCode)
-}
-
-func compareUsage(want, got string, t *testing.T) {
- got = strings.Replace(got, " ", ".", -1)
- if want != got {
- shortest := len(want)
- if len(got) < shortest {
- shortest = len(got)
- }
- if len(want) != len(got) {
- t.Errorf("expected result length of %d, found %d",
len(want), len(got))
- }
- for i := 0; i < shortest; i++ {
- if want[i] != got[i] {
- t.Errorf("difference at index %d, expected '%c'
(%v), found '%c' (%v)\n",
- i, want[i], want[i], got[i], got[i])
- break
- }
- }
- t.Errorf("Complete Expected:\n'%s'\nComplete Found:\n'%s'\n",
want, got)
- }
-}
-
-func TestUsageDefault(t *testing.T) {
- var s Specification
- os.Clearenv()
- save := os.Stdout
- r, w, _ := os.Pipe()
- os.Stdout = w
- err := Usage("env_config", &s)
- outC := make(chan string)
- // copy the output in a separate goroutine so printing can't block
indefinitely
- go func() {
- var buf bytes.Buffer
- io.Copy(&buf, r)
- outC <- buf.String()
- }()
- w.Close()
- os.Stdout = save // restoring the real stdout
- out := <-outC
-
- if err != nil {
- t.Error(err.Error())
- }
- compareUsage(testUsageTableResult, out, t)
-}
-
-func TestUsageTable(t *testing.T) {
- var s Specification
- os.Clearenv()
- buf := new(bytes.Buffer)
- tabs := tabwriter.NewWriter(buf, 1, 0, 4, ' ', 0)
- err := Usagef("env_config", &s, tabs, DefaultTableFormat)
- tabs.Flush()
- if err != nil {
- t.Error(err.Error())
- }
- compareUsage(testUsageTableResult, buf.String(), t)
-}
-
-func TestUsageList(t *testing.T) {
- var s Specification
- os.Clearenv()
- buf := new(bytes.Buffer)
- err := Usagef("env_config", &s, buf, DefaultListFormat)
- if err != nil {
- t.Error(err.Error())
- }
- compareUsage(testUsageListResult, buf.String(), t)
-}
-
-func TestUsageCustomFormat(t *testing.T) {
- var s Specification
- os.Clearenv()
- buf := new(bytes.Buffer)
- err := Usagef("env_config", &s, buf, "{{range .}}{{usage_key
.}}={{usage_description .}}\n{{end}}")
- if err != nil {
- t.Error(err.Error())
- }
- compareUsage(testUsageCustomResult, buf.String(), t)
-}
-
-func TestUsageUnknownKeyFormat(t *testing.T) {
- var s Specification
- unknownError := "template: envconfig:1:2: executing \"envconfig\" at
<.UnknownKey>"
- os.Clearenv()
- buf := new(bytes.Buffer)
- err := Usagef("env_config", &s, buf, "{{.UnknownKey}}")
- if err == nil {
- t.Errorf("expected 'unknown key' error, but got no error")
- }
- if strings.Index(err.Error(), unknownError) == -1 {
- t.Errorf("expected '%s', but got '%s'", unknownError,
err.Error())
- }
-}
-
-func TestUsageBadFormat(t *testing.T) {
- var s Specification
- os.Clearenv()
- // If you don't use two {{}} then you get a lieteral
- buf := new(bytes.Buffer)
- err := Usagef("env_config", &s, buf, "{{range .}}{.Key}\n{{end}}")
- if err != nil {
- t.Error(err.Error())
- }
- compareUsage(testUsageBadFormatResult, buf.String(), t)
-}