File: env_windows_test.go

package info (click to toggle)
golang-golang-x-sys 0.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 10,596 kB
  • sloc: asm: 6,462; sh: 933; ansic: 51; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package windows_test

import (
	"fmt"
	"slices"
	"testing"

	"golang.org/x/sys/windows"
)

func TestEnvironUTF8(t *testing.T) {
	testEnvVariable1Key := "__GO_X_SYS_WINDOWS_ENV_WINDOWS_TEST_VAR_BEAVER"
	testEnvVariable1Val := "🦫"
	t.Setenv(testEnvVariable1Key, testEnvVariable1Val)

	testEnvVariable2Key := "__GO_X_SYS_WINDOWS_ENV_WINDOWS_TEST_VAR_WHALE"
	testEnvVariable2Val := "🐳"
	t.Setenv(testEnvVariable2Key, testEnvVariable2Val)

	var userToken windows.Token

	env, err := userToken.Environ(true)
	if err != nil {
		t.Error(err)
	}

	testEnvVariable1 := fmt.Sprintf("%s=%s", testEnvVariable1Key, testEnvVariable1Val)
	if !slices.Contains(env, testEnvVariable1) {
		t.Fatalf("expected to find %s in env", testEnvVariable1)
	}

	testEnvVariable2 := fmt.Sprintf("%s=%s", testEnvVariable2Key, testEnvVariable2Val)
	if !slices.Contains(env, testEnvVariable2) {
		t.Fatalf("expected to find %s in env", testEnvVariable2)
	}
}