diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4b86fc6d639fd7008316bd08dcd44fe47a41f54e..75e5f4e7f15905929f2d38422a05931e3dd8bfdf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,19 +1,19 @@ workflow: rules: # For merge requests, create a pipeline. - - if: '$CI_MERGE_REQUEST_IID' + - if: "$CI_MERGE_REQUEST_IID" # For default branch, create a pipeline (this includes on schedules, pushes, merges, etc.). # - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' # Temporarly create Ci for every branch: - - if: '$CI_COMMIT_BRANCH' + - if: "$CI_COMMIT_BRANCH" # For tags, create a pipeline. - - if: '$CI_COMMIT_TAG' + - if: "$CI_COMMIT_TAG" # For stable branches, create a pipeline. - if: '$CI_COMMIT_BRANCH =~ /^[\d-]+-stable$/' # default: - image: golang:1.15 + image: golang:1.18 variables: SAST_EXCLUDED_ANALYZERS: "bandit,gosec,eslint" @@ -31,3 +31,16 @@ code_navigation: artifacts: reports: lsif: dump.lsif + +run_tests: + before_script: + ## Adding private SSH key to the executor, more information: https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan gitlab.com >> ~/.ssh/known_hosts + - chmod 600 ~/.ssh/known_hosts + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + + script: + - make test diff --git a/commands/ci/trace/trace_test.go b/commands/ci/trace/trace_test.go index 73d98846ef4d85b959dcb220973b558c412ad7fd..5975cead7fa355a57224a36c8e64d24a601de767 100644 --- a/commands/ci/trace/trace_test.go +++ b/commands/ci/trace/trace_test.go @@ -46,13 +46,15 @@ hosts: repo := cmdtest.CopyTestRepo(t, "ci_trace_test") gitCmd := exec.Command("git", "fetch", "origin") gitCmd.Dir = repo - if _, err := gitCmd.CombinedOutput(); err != nil { + if out, err := gitCmd.CombinedOutput(); err != nil { + t.Error(string(out)) t.Fatal(err) } gitCmd = exec.Command("git", "checkout", "test-cli") gitCmd.Dir = repo - if _, err := gitCmd.CombinedOutput(); err != nil { + if out, err := gitCmd.CombinedOutput(); err != nil { + t.Error(string(out)) t.Fatal(err) } diff --git a/commands/cmdutils/cmdutils_test.go b/commands/cmdutils/cmdutils_test.go index 590932ea70676f210264f6fc7e3d8b9879a585ea..f6374427272c7ba04259ebf81e350e8ff23f86b4 100644 --- a/commands/cmdutils/cmdutils_test.go +++ b/commands/cmdutils/cmdutils_test.go @@ -259,7 +259,7 @@ func Test_UserAssignmentsAPIFailure(t *testing.T) { t.Errorf("UsersFromReplaces() expected error to not be nil") } if want != err.Error() { - t.Errorf("UsersFromReplace() expected error = %s, got = %w", want, err) + t.Errorf("UsersFromReplace() expected error = %s, got = %v", want, err) } _, _, err = ua.UsersFromAddRemove(nil, nil, &apiClient, nil) @@ -267,7 +267,7 @@ func Test_UserAssignmentsAPIFailure(t *testing.T) { t.Errorf("UsersFromReplaces() expected error to not be nil") } if want != err.Error() { - t.Errorf("UsersFromReplace() expected error = %s, got = %w", want, err) + t.Errorf("UsersFromReplace() expected error = %s, got = %v", want, err) } } diff --git a/pkg/git/git_test.go b/pkg/git/git_test.go index 9d57a806f96679aaed441810391f0f57899a298e..a42594fc8ee43c64959c7b7405bb0d9e791867a3 100644 --- a/pkg/git/git_test.go +++ b/pkg/git/git_test.go @@ -1,6 +1,7 @@ package git import ( + "os" "os/exec" "reflect" "testing" @@ -13,6 +14,13 @@ import ( "github.com/stretchr/testify/require" ) +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} + func Test_isFilesystemPath(t *testing.T) { type args struct { p string @@ -291,7 +299,7 @@ func TestGetRemoteURL(t *testing.T) { { name: "isInvalid", remoteAlias: "origin", - want: "profclems/glab", + want: getEnv("CI_PROJECT_PATH","gitlab-org/cli"), }, } for _, tt := range tests {