File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments