Skip to content

Commit

Permalink
chore(gh-action): add go versions matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Feb 26, 2022
1 parent 9c6ad4b commit c9901c7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/pr.yml → .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@

name: Tests
name: Go

on:
pull_request:
paths-ignore:
- "docs/**"
- "images/**"
- "*.md"
branches:
- master
push:
paths-ignore:
- "images/**"
- "*.md"
branches:
- master
Expand All @@ -14,9 +20,12 @@ jobs:
name: Run linting
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: "latest"
args: -c ./golangci.yml
Expand All @@ -26,7 +35,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
go: [1.x]
go: ["1.16.x", "1.17.x"]
steps:
- name: Set git to use LF
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<br>

[![Tests](https://github.com/gkampitakis/go-snaps/actions/workflows/pr.yml/badge.svg)](https://github.com/gkampitakis/go-snaps/actions/workflows/pr.yml)
[![Go](https://github.com/gkampitakis/go-snaps/actions/workflows/go.yml/badge.svg?branch=master)](https://github.com/gkampitakis/go-snaps/actions/workflows/go.yml)

## Installation

Expand Down
27 changes: 24 additions & 3 deletions snaps/env_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package snaps

import "testing"
import (
"os"
"testing"
)

// NOTE: this was added at 1.17
func setEnv(t *testing.T, key, value string) {
t.Helper()

prevVal, exists := os.LookupEnv(key)
os.Setenv(key, value)

if exists {
t.Cleanup(func() {
os.Setenv(key, prevVal)
})
} else {
t.Cleanup(func() {
os.Unsetenv(key)
})
}
}

func TestEnv(t *testing.T) {
t.Run("should return true if env var is 'true'", func(t *testing.T) {
t.Setenv("MOCK_ENV", "true")
setEnv(t, "MOCK_ENV", "true")

res := getEnvBool("MOCK_ENV", false)

Expand All @@ -14,7 +35,7 @@ func TestEnv(t *testing.T) {
})

t.Run("should return false", func(t *testing.T) {
t.Setenv("MOCK_ENV", "")
setEnv(t, "MOCK_ENV", "")

res := getEnvBool("MOCK_ENV", true)

Expand Down

0 comments on commit c9901c7

Please sign in to comment.