Skip to content

go linter that check whether environment variables are set in tests run in parallel

License

Notifications You must be signed in to change notification settings

sho-hata/parallelenv

Repository files navigation

parallelenv

go linter that check whether environment variables are set in tests run in parallel

Motivation

Calls to t.Parallel() and t.Setenv() in the test function will cause a panic, as environment variables cannot be set in tests that run in parallel.

We created this tool in the hope that it would be noticed by static analysis before the tests are run.

test_and_lint

installation

go install github.com/sho-hata/parallelenv/cmd/parallelenv@latest

Usage

test file Example

package main

import (
	"testing"
)

func TestMain(t *testing.T) {
  t.Parallel()
  t.Setenv("LANGUAGE", "Go")
}

Analysis

$ parallelenv ./...

./main_test.go:7:2: cannot set environment variables in parallel tests
./main_test.go:8:2: cannot set environment variables in parallel tests

CI

CircleCI

- run:
    name: install parallelenv
    command: go install github.com/sho-hata/parallelenv/cmd/parallelenv@latest

- run:
    name: run parallelenv
    command: parallelenv ./...

GitHub Actions

- name: install parallelenv
  run: go install github.com/sho-hata/parallelenv/cmd/parallelenv@latest

- name: run parallelenv
  run: parallelenv ./...

About

go linter that check whether environment variables are set in tests run in parallel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages