Skip to content

Commit

Permalink
use t.Setenv for gcp detector
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Feb 13, 2025
1 parent 450ed4e commit 6e6a1be
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions detectors/gcp/cloud-function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package gcp
import (
"context"
"errors"
"os"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -57,20 +56,8 @@ type want struct {
}

func TestCloudFunctionDetect(t *testing.T) {
oldValue, ok := os.LookupEnv(gcpFunctionNameKey)
if !ok {
err := os.Setenv(gcpFunctionNameKey, functionName)
if err != nil {
t.Error("unable to set environment variable ", err)
}
}
defer func() {
if !ok {
_ = os.Unsetenv(gcpFunctionNameKey)
} else {
_ = os.Setenv(gcpFunctionNameKey, oldValue)
}
}()
t.Setenv(gcpFunctionNameKey, functionName)

tests := []struct {
name string
cr *CloudRun
Expand Down Expand Up @@ -143,15 +130,6 @@ func TestCloudFunctionDetect(t *testing.T) {
}

func TestNotOnCloudFunction(t *testing.T) {
oldValue, ok := os.LookupEnv(gcpFunctionNameKey)
if ok {
_ = os.Unsetenv(gcpFunctionNameKey)
}
defer func() {
if ok {
_ = os.Setenv(gcpFunctionNameKey, oldValue)
}
}()
detector := NewCloudFunction()
res, err := detector.Detect(context.Background())
if err != nil {
Expand Down

0 comments on commit 6e6a1be

Please sign in to comment.