Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
efirs committed Jun 7, 2023
1 parent b632f1f commit fd5c37f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 30 deletions.
41 changes: 36 additions & 5 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.20'

- run: sudo apt-get install jq
if: matrix.os == 'ubuntu-latest'
Expand All @@ -37,8 +33,43 @@ jobs:
- name: Run tests
run: |
mkdir /tmp/tigris_cli_coverdata
GOCOVERDIR=/tmp/tigris_cli_coverdata/ BUILD_PARAM=-cover TIGRIS_CLI_TEST_FAST=1 make test
SUDO=sudo GOCOVERDIR=/tmp/tigris_cli_coverdata/ BUILD_PARAM=-cover TIGRIS_CLI_TEST_FAST=1 make test
go tool covdata textfmt -i=/tmp/tigris_cli_coverdata/ -o coverage.out
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3

# FIXME: same as above, with TIGRIS_CLI_TEST_FAST=1 removed.
# Work on unifying.
test-all:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macOS-latest ]
steps:
- name: Checkout code
uses: actions/checkout@v3

- run: sudo apt-get install jq
if: matrix.os == 'ubuntu-latest'

- if: matrix.os == 'macOS-latest'
run: |
brew install jq colima docker docker-compose tree
colima start
mkdir -p ~/.docker/cli-plugins
ln -sfn $(brew --prefix)/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
- run: chocolatey install jq
if: matrix.os == 'windows-latest'

- run: npm install -g @go-task/cli

- name: Run tests
run: |
mkdir /tmp/tigris_cli_coverdata_all
SUDO=sudo GOCOVERDIR=/tmp/tigris_cli_coverdata_all/ BUILD_PARAM=-cover make test
go tool covdata textfmt -i=/tmp/tigris_cli_coverdata_all/ -o coverage.out
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/test-pkg-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:

- name: Windows
run: sh scripts/test_pkg_install.sh
if: false || matrix.os == 'windows-latest'
if: matrix.os == 'windows-latest'
14 changes: 9 additions & 5 deletions cmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ func setupToken() {
cfg.Protocol = "http"
}

func getLocalURL(local bool, port string, dataDir string) string {
if local && !tokenAdminAuth && config.DefaultConfig.Token == "" {
return dataDir + "/server/unix.sock"
}

return net.JoinHostPort("localhost", port)
}

func localUp(cmd *cobra.Command, args []string, local bool) {
cli := getClient(cmd.Context())

Expand All @@ -347,11 +355,7 @@ func localUp(cmd *cobra.Command, args []string, local bool) {

cfg := &config.DefaultConfig

if local && !tokenAdminAuth && cfg.Token == "" {
cfg.URL = dataDir + "/server/unix.sock"
} else {
cfg.URL = net.JoinHostPort("localhost", port)
}
cfg.URL = getLocalURL(local, port, dataDir)

waitServerUp(cfg.URL, false)

Expand Down
5 changes: 4 additions & 1 deletion login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ func isUnixSock(url string) bool {
}

func isLocalConn(host string) bool {
return host == "local" || host == "dev" || strings.HasPrefix(host, "localhost") ||
return host == "local" || host == "dev" || host == "localhost" ||
strings.HasPrefix(host, "localhost:") ||
strings.HasPrefix(host, "127.0.0.1:") ||
strings.HasPrefix(host, "[::1]:") ||
isUnixSock(host)
}

Expand Down
4 changes: 2 additions & 2 deletions scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func ensureLocalTemplates(base string, lang string, envVar string, repoURL strin
if os.Getenv(envVar) != "" {
// Do not allow remote path substitution
_, err := url.ParseRequestURI(os.Getenv(envVar))
if err == nil && !os.IsPathSeparator(repoURL[0]) {
util.Fatal(ErrTemplatesInvalidPath, "get examples path from env")
if err == nil && !os.IsPathSeparator(os.Getenv(envVar)[0]) {
util.Fatal(ErrTemplatesInvalidPath, "get examples path from env: %s", os.Getenv(envVar))
}

repoURL = os.Getenv(envVar)
Expand Down
5 changes: 4 additions & 1 deletion tests/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ main() {

if [ -z "$TIGRIS_CLI_TEST_FAST" ]; then
test_scaffold
test_persistence
fi

# Exercise tests via GRPC
Expand Down Expand Up @@ -474,6 +473,10 @@ main() {
$cli config show | grep "protocol: http"
$cli config show | grep "url: grpc://localhost:$TIGRIS_TEST_PORT"
db_tests

if [ -z "$TIGRIS_CLI_TEST_FAST" ]; then
test_persistence
fi
}

main
Expand Down
17 changes: 7 additions & 10 deletions tests/persistence.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#!/bin/bash

set -ex
PS4='${LINENO}: '

if [ -z "$cli" ]; then
cli="$(pwd)/tigris"
cli="./tigris"
fi

if [ -z "$TIGRIS_TEST_PORT" ]; then
TIGRIS_TEST_PORT=8090
fi

cli="$SUDO $cli"

DATA_DIR=/tmp/tigris-cli-local-test

test_persistence_low() {
rm -rf $DATA_DIR
rm "$HOME/.tigris/tigris-cli.yaml"
$SUDO rm -rf $DATA_DIR
rm -f "$HOME/.tigris/tigris-cli.yaml"

#shellcheck disable=SC2086
$cli local up --data-dir=$DATA_DIR $1 $2
[ -f $DATA_DIR/initialized ] || exit 1

env|grep TIGRIS
$cli config show
$cli create project persistence_test
$cli list projects|grep persistence_test

Expand All @@ -44,6 +41,6 @@ test_persistence_low() {
}

test_persistence() {
HOME=/tmp/ test_persistence_low
HOME=/tmp/ TIGRIS_URL=localhost:$TIGRIS_TEST_PORT test_persistence_low --token-admin-auth "$TIGRIS_TEST_PORT"
TIGRIS_URL="" HOME=/tmp/ cli="$SUDO $cli" test_persistence_low
TIGRIS_URL="" HOME=/tmp/ cli="$SUDO $cli" TIGRIS_URL=localhost:$TIGRIS_TEST_PORT test_persistence_low --token-admin-auth "$TIGRIS_TEST_PORT"
}
10 changes: 5 additions & 5 deletions tests/scaffold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $cli config show
env|grep TIGRIS

#if [ -z "$noup" ]; then
# $cli local up
# $cli dev start
#fi

# first parameter is path
Expand Down Expand Up @@ -84,7 +84,7 @@ clean() {

scaffold() {
if [ -z "$noup" ]; then
$cli local up "$TIGRIS_TEST_PORT"
$cli dev start "$TIGRIS_TEST_PORT"
fi

clean
Expand All @@ -99,7 +99,7 @@ scaffold() {
--output-directory="$outdir"

if [ -z "$noup" ]; then
$cli local down
$cli dev stop
fi
}

Expand All @@ -121,7 +121,7 @@ test_gin_go() {

# instance was stopped by the 'task' target, bring it back
if [ -z "$noup" ]; then
$cli local up "$TIGRIS_TEST_PORT"
$cli dev start "$TIGRIS_TEST_PORT"
fi

clean
Expand Down Expand Up @@ -210,6 +210,6 @@ test_scaffold() {
test_nextjs_typescript

if [ -z "$noup" ]; then
$cli local up "$TIGRIS_TEST_PORT"
$cli dev start "$TIGRIS_TEST_PORT"
fi
}

0 comments on commit fd5c37f

Please sign in to comment.