Skip to content

Commit a525ad5

Browse files
add simple test for ReadContents
1 parent bfd0e1f commit a525ad5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

minikube/state_utils/io_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package state_utils
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"testing"
7+
)
8+
9+
func TestReadContents(t *testing.T) {
10+
// Create a temporary file for testing
11+
tempFile, err := ioutil.TempFile("", "test")
12+
if err != nil {
13+
t.Fatalf("Error creating temp file: %v", err)
14+
}
15+
defer os.Remove(tempFile.Name())
16+
17+
// Write some content to the temporary file
18+
testContent := "This is a test content."
19+
_, err = tempFile.WriteString(testContent)
20+
if err != nil {
21+
t.Fatalf("Error writing to temp file: %v", err)
22+
}
23+
24+
// Close the temporary file
25+
tempFile.Close()
26+
27+
// Test the ReadContents function
28+
result, err := ReadContents(tempFile.Name())
29+
if err != nil {
30+
t.Fatalf("Error reading contents: %v", err)
31+
}
32+
33+
// Check if the content read matches the expected content
34+
if result != testContent {
35+
t.Errorf("Expected content '%s', got '%s'", testContent, result)
36+
}
37+
}

0 commit comments

Comments
 (0)