Fix unit-tests

This commit is contained in:
Dmitrii Okunev 2021-06-25 13:55:22 +01:00
parent b993420c80
commit ea5128898b
3 changed files with 10 additions and 1 deletions

View File

@ -15,5 +15,5 @@ func TestMultiErrorMarshalJSON(t *testing.T) {
var errDescr string
err = json.Unmarshal(b, &errDescr)
require.NoError(t, err, string(b))
require.Equal(t, `"errors: simple error message; I am a citizen of \"Earth\"!"`, string(b))
require.Equal(t, `"errors: simple error message; I am a citizen of \"Earth\""`, string(b))
}

View File

@ -92,6 +92,9 @@ func local(devicePath, capabilities string) (Type, error) {
for _, lineBytes := range bytes.Split(caps, []byte{'\n'}) {
line := string(lineBytes)
parts := strings.SplitN(line, ":", 2)
if len(parts) != 2 {
return 0, fmt.Errorf("unable to split line '%s'", line)
}
key := strings.TrimSpace(parts[0])
val := strings.TrimSpace(parts[1])
if key == specPrefix {

View File

@ -1,6 +1,7 @@
package tpmdetection
import (
"fmt"
"io/ioutil"
"os"
"path"
@ -61,7 +62,12 @@ func TestTPMDetection(t *testing.T) {
t.Errorf("Failed to create local file: %s, err: %v", devicePath, err)
t.Skip()
}
if _, err = fmt.Fprintf(f, "TCG version: %s", capTPMVersion); err != nil {
t.Errorf("unable to write to the capabilities file: %v", err)
t.Skip()
}
_ = f.Close()
defer func() {
err := os.Remove(capabilitiesPath)
if err != nil {