|
|
|
protocol/contracts_test.go raw
| 1 | package protocol_test | | 2 | | | 3 | import ( | | 4 | "os" | | 5 | "os/exec" | | 6 | "path/filepath" | | 7 | "runtime" | | 8 | "strconv" | | 9 | "strings" | | 10 | "testing" | | 11 | ) | | 12 | | | 13 | const modulePath = "github.com/FelineStateMachine/tinyrelay" | | 14 | | | 15 | // Run a real consumer outside tinyrelay's module so Go's internal import | | 16 | // restriction, public type identity and standalone dependencies are checked. | | 17 | func TestExternalNostrConsumer(t *testing.T) { | | 18 | runConsumer(t, "nostr" ) | | 19 | } | | 20 | | | 21 | func TestExternalAuthConsumer(t *testing.T) { | | 22 | runConsumer(t, "auth" ) | | 23 | } | | 24 | | | 25 | func runConsumer(t *testing.T, fixture string) { | | 26 | t.Helper() | | 27 | root, err := filepath.Abs(".." ) | | 28 | if err != nil { | | 29 | t.Fatal(err) | | 30 | } | | 31 | mod, err := os.ReadFile(filepath.Join(root, "go.mod" )) | | 32 | if err != nil { | | 33 | t.Fatal(err) | | 34 | } | | 35 | var goVersion string | | 36 | for _, line := range strings.Split(string(mod), "\n" ) { | | 37 | if strings.HasPrefix(line, "go " ) { | | 38 | goVersion = strings.TrimPrefix(line, "go " ) | | 39 | } | | 40 | } | | 41 | if goVersion == "" { | | 42 | t.Fatal("module has no Go version" ) | | 43 | } | | 44 | dir := t.TempDir() | | 45 | write := func(name string, data []byte) { | | 46 | t.Helper() | | 47 | if err := os.WriteFile(filepath.Join(dir, name), data, 0600); err != nil { | | 48 | t.Fatal(err) | | 49 | } | | 50 | } | | 51 | write("go.mod" , []byte("module example.com/protocol-consumer\n\ngo " +goVersion+"\n\nrequire " +modulePath+" v0.0.0\nreplace " +modulePath+" => " +strconv.Quote(filepath.ToSlash(root))+"\n" )) | | 52 | for _, file := range []struct{ src, dst string }{ | | 53 | {filepath.Join(root, "go.sum" ), "go.sum" }, | | 54 | {filepath.Join("testdata" , fixture, "consumer_test.go" ), "consumer_test.go" }, | | 55 | } { | | 56 | data, err := os.ReadFile(file.src) | | 57 | if err != nil { | | 58 | t.Fatal(err) | | 59 | } | | 60 | write(file.dst, data) | | 61 | } | | 62 | cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin" , "go" ), "test" , "-mod=mod" , "-count=1" , "./..." ) | | 63 | cmd.Dir = dir | | 64 | cmd.Env = append(os.Environ(), "GOWORK=off" ) | | 65 | if out, err := cmd.CombinedOutput(); err != nil { | | 66 | t.Fatalf("external %s consumer: %v\n%s" , fixture, err, out) | | 67 | } | | 68 | } |
|
|
About| owner | c01503e8035f |
|---|
| visibility | public |
|---|
| head | d730679639bf |
|---|
Maintainers- c01503e8035f owner
- ba1b5beed5b5 agent hermes
Clonehttps://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git
|