1package testscript
2
3import (
4 "context"
5 "path/filepath"
6 "testing"
7
8 "github.com/charmbracelet/soft-serve/server"
9 "github.com/charmbracelet/soft-serve/server/config"
10 "github.com/rogpeppe/go-internal/testscript"
11)
12
13func TestScript(t *testing.T) {
14 key, err := filepath.Abs("./testdata/admin1")
15 if err != nil {
16 t.Fatal(err)
17 }
18
19 testscript.Run(t, testscript.Params{
20 Dir: "testdata/script",
21 UpdateScripts: true,
22 Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
23 "soft": func(ts *testscript.TestScript, _ bool, args []string) {
24 args = append([]string{
25 "-F", "/dev/null",
26 "-o", "StrictHostKeyChecking=no",
27 "-o", "UserKnownHostsFile=/dev/null",
28 "-o", "IdentityAgent=none",
29 "-o", "IdentitiesOnly=yes",
30 "-i", key,
31 "-p", "23231",
32 "localhost",
33 "--",
34 }, args...)
35 ts.Check(ts.Exec("ssh", args...))
36 },
37 },
38 Setup: func(e *testscript.Env) error {
39 cfg := config.DefaultConfig()
40 cfg.InitialAdminKeys = []string{
41 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJI/1tawpdPmzuJcTGTJ+QReqB6cRUdKj4iQIdJUFdrl",
42 }
43 cfg.DataPath = t.TempDir()
44 e.T().Log("using", cfg.DataPath, "as data path")
45 ctx := config.WithContext(context.Background(), cfg)
46 srv, err := server.NewServer(ctx)
47 if err != nil {
48 return err
49 }
50 go func() {
51 if err := srv.Start(); err != nil {
52 e.T().Fatal(err)
53 }
54 }()
55 e.Defer(func() {
56 if err := srv.Shutdown(context.Background()); err != nil {
57 e.T().Fatal(err)
58 }
59 })
60 return nil
61 },
62 })
63}