Debian Codegraph @

internal/emit_no_cgo_test.go

raw
1 //go:build !no_antithesis_sdk && linux && amd64 && !cgo
2
3 package internal
4
5 import (
6 "os"
7 "path/filepath"
8 "testing"
9 )
10
11 func TestNoCgoRunsInDegradedMode(t *testing.T) {
12 if !sdkRunningInDegradedMode {
13 t.Fatal("expected sdkRunningInDegradedMode to be true in the no-cgo build")
14 }
15 }
16
17 func TestNoCgoInitReturnsNilWithoutOutputDir(t *testing.T) {
18 os.Unsetenv(outputDirEnvVar)
19 if h := init_in_antithesis(); h != nil {
20 t.Fatalf("expected nil handler when %s is unset, got %T", outputDirEnvVar, h)
21 }
22
23 os.Setenv(outputDirEnvVar, "")
24 defer os.Unsetenv(outputDirEnvVar)
25 if h := init_in_antithesis(); h != nil {
26 t.Fatalf("expected nil handler when %s is empty, got %T", outputDirEnvVar, h)
27 }
28 }
29
30 func TestNoCgoInitWritesToSdkJsonl(t *testing.T) {
31 dir := t.TempDir()
32 os.Setenv(outputDirEnvVar, dir)
33 defer os.Unsetenv(outputDirEnvVar)
34
35 h := init_in_antithesis()
36 if h == nil {
37 t.Fatalf("expected a handler when %s is set", outputDirEnvVar)
38 }
39 if _, ok := h.(*inAntithesisWithoutCgoHandler); !ok {
40 t.Fatalf("expected *inAntithesisWithoutCgoHandler, got %T", h)
41 }
42
43 h.output(`{"antithesis_sdk":"first"}`)
44 h.(*inAntithesisWithoutCgoHandler).outputFile.Close()
45
46 path := filepath.Join(dir, fallbackOutputFilename)
47 data, err := os.ReadFile(path)
48 if err != nil {
49 t.Fatalf("expected %s to exist: %v", path, err)
50 }
51 if got := string(data); got != `{"antithesis_sdk":"first"}`+"\n" {
52 t.Fatalf("unexpected file contents: %q", got)
53 }
54 }