parallelenv

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2022 License: MIT Imports: 6 Imported by: 0

README

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

Instruction

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
$ go vet -vettool=(which 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: go vet -vettool=`which parallelenv` ./...
GitHub Actions
- name: install parallelenv
  run: go install github.com/sho-hata/parallelenv/cmd/parallelenv@latest

- name: run parallelenv
  run: go vet -vettool=`which parallelenv` ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "parallelenv",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL