github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/k6runner/env_test.go (about)

     1  package k6runner
     2  
     3  import (
     4  	"slices"
     5  	"testing"
     6  )
     7  
     8  func TestEnv(t *testing.T) {
     9  	t.Parallel()
    10  
    11  	t.Run("adds default variables", func(t *testing.T) {
    12  		t.Parallel()
    13  
    14  		osenv := []string{"SOMETHING=else", "FOO=bar"}
    15  		modified := k6Env(osenv)
    16  
    17  		if !slices.Contains(modified, "K6_BROWSER_LOG=info") {
    18  			t.Fatalf("Expected env to contain browser log info")
    19  		}
    20  
    21  		if !slices.Contains(modified, "K6_AUTO_EXTENSION_RESOLUTION=false") {
    22  			t.Fatalf("Expected env to contain K6_AUTO_EXTENSION_RESOLUTION")
    23  		}
    24  	})
    25  
    26  	t.Run("does not modify existing value", func(t *testing.T) {
    27  		t.Parallel()
    28  
    29  		osenv := []string{"SOMETHING=else", "FOO=bar", "K6_BROWSER_LOG=debug", "K6_AUTO_EXTENSION_RESOLUTION=true"}
    30  		modified := k6Env(osenv)
    31  
    32  		if !slices.Contains(modified, "K6_BROWSER_LOG=debug") {
    33  			t.Fatalf("Expected env to contain original variable")
    34  		}
    35  
    36  		if !slices.Contains(modified, "K6_AUTO_EXTENSION_RESOLUTION=true") {
    37  			t.Fatalf("Expected env to contain original variable")
    38  		}
    39  
    40  		if slices.Contains(modified, "K6_BROWSER_LOG=info") {
    41  			t.Fatalf("Expected env to _not_ contain browser log info")
    42  		}
    43  	})
    44  }