| 1 |
//go:build !no_antithesis_sdk |
| 2 |
|
| 3 |
package internal |
| 4 |
|
| 5 |
import ( |
| 6 |
"encoding/json" |
| 7 |
"os" |
| 8 |
"testing" |
| 9 |
) |
| 10 |
|
| 11 |
func TestLocalHandlerFileOutput(t *testing.T) { |
| 12 |
path := t.TempDir() + string(os.PathSeparator) + "antithesis-test.log" |
| 13 |
os.Setenv(localOutputEnvVar, path) |
| 14 |
defer os.Unsetenv(localOutputEnvVar) |
| 15 |
handler = openLocalHandler() |
| 16 |
Json_data(map[string]string{ |
| 17 |
"test": "output", |
| 18 |
}) |
| 19 |
handler.(*localHandler).outputFile.Close() |
| 20 |
data, err := os.ReadFile(path) |
| 21 |
if err != nil { |
| 22 |
panic(err) |
| 23 |
} |
| 24 |
var result map[string]string |
| 25 |
if err = json.Unmarshal(data, &result); err != nil { |
| 26 |
panic(err) |
| 27 |
} |
| 28 |
if result["test"] != "output" { |
| 29 |
panic("JSON does not roundtrip") |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
func TestLocalHandlerNop(t *testing.T) { |
| 34 |
os.Setenv(localOutputEnvVar, "") |
| 35 |
defer os.Unsetenv(localOutputEnvVar) |
| 36 |
handler = openLocalHandler() |
| 37 |
Json_data(map[string]string{ |
| 38 |
"test": "output", |
| 39 |
}) |
| 40 |
h, valid := handler.(*localHandler) |
| 41 |
if !valid { |
| 42 |
panic("Not using the local handler") |
| 43 |
} |
| 44 |
if h.outputFile != nil { |
| 45 |
panic("Should not be outputting to file") |
| 46 |
} |
| 47 |
} |