File: telemetry_test.go

package info (click to toggle)
golang-github-crc-org-crc 2.34.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,548 kB
  • sloc: sh: 398; makefile: 326; javascript: 40
file content (27 lines) | stat: -rw-r--r-- 761 bytes parent folder | download
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
package telemetry

import (
	"errors"
	"fmt"
	"os/user"
	"testing"

	"github.com/crc-org/crc/v2/pkg/crc/constants"
	"github.com/stretchr/testify/assert"
)

func TestSetError(t *testing.T) {
	err := errors.New("this is an error string")
	assert.Equal(t, err.Error(), SetError(err))

	user, err := user.Current()
	assert.NoError(t, err)

	err = fmt.Errorf("cannot access storage file '%s/.crc/machines/crc/crc.qcow2' (as uid:64055, gid:129): Permission denied')", constants.GetHomeDir())
	assert.NotEqual(t, err.Error(), SetError(err))
	assert.NotContains(t, SetError(err), constants.GetHomeDir())

	err = fmt.Errorf("user %s may not use sudo", user.Username)
	assert.NotEqual(t, err.Error(), SetError(err))
	assert.NotContains(t, SetError(err), user.Username)
}