Skip to content

Commit 0238b7b

Browse files
committed
test: tmp file from embed.FS
On-behalf-of: @SAP [email protected] Signed-off-by: Christopher Junk <[email protected]>
1 parent b9ea76e commit 0238b7b

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/openmcp-project/openmcp-testing
33
go 1.25.2
44

55
require (
6+
github.com/stretchr/testify v1.10.0
67
github.com/vladimirvivien/gexe v0.4.1
78
k8s.io/api v0.34.2
89
k8s.io/apimachinery v0.34.2
@@ -16,6 +17,7 @@ require (
1617
github.com/BurntSushi/toml v1.4.0 // indirect
1718
github.com/mattn/go-isatty v0.0.20 // indirect
1819
github.com/pelletier/go-toml v1.9.5 // indirect
20+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
1921
go.yaml.in/yaml/v2 v2.4.2 // indirect
2022
go.yaml.in/yaml/v3 v3.0.4 // indirect
2123
sigs.k8s.io/randfill v1.0.0 // indirect

internal/testdata/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello openmcp!

internal/util_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package internal
2+
3+
import (
4+
"bufio"
5+
"embed"
6+
"os"
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
//go:embed testdata/test.txt
13+
var testFS embed.FS
14+
15+
func TestMustTmpFileFromEmbedFS(t *testing.T) {
16+
result := MustTmpFileFromEmbedFS(testFS, "testdata/test.txt")
17+
file, err := os.Open(result)
18+
require.NoError(t, err)
19+
scanner := bufio.NewScanner(file)
20+
require.True(t, scanner.Scan())
21+
require.Equal(t, scanner.Text(), "hello openmcp!")
22+
os.RemoveAll(result)
23+
}

0 commit comments

Comments
 (0)