-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathhash_test.go
More file actions
44 lines (34 loc) · 1.07 KB
/
hash_test.go
File metadata and controls
44 lines (34 loc) · 1.07 KB
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
43
44
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package fsutil_test
import (
"path/filepath"
"testing"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"go.mondoo.com/mql/v13/providers-sdk/v1/inventory"
"go.mondoo.com/mql/v13/providers/os/connection/local"
"go.mondoo.com/mql/v13/providers/os/fsutil"
)
func TestFileResource(t *testing.T) {
path := filepath.Join(t.TempDir(), "test_hash")
conn := local.NewConnection(0, &inventory.Config{
Path: path,
}, &inventory.Asset{})
fs := conn.FileSystem()
afutil := afero.Afero{Fs: fs}
// create the file and set the content
err := afutil.WriteFile(path, []byte("hello world"), 0o666)
assert.Nil(t, err)
f, err := fs.Open(path)
assert.Nil(t, err)
if assert.NotNil(t, f) {
assert.Equal(t, path, f.Name(), "they should be equal")
md5, err := fsutil.Md5(f)
assert.Nil(t, err)
assert.Equal(t, "5eb63bbbe01eeed093cb22bb8f5acdc3", md5)
sha256, err := fsutil.Sha256(f)
assert.Nil(t, err)
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", sha256)
}
}