This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / spindle / server_test.go
2.5 kB 101 lines
1package spindle 2 3import ( 4 "context" 5 "net/http" 6 "net/http/httptest" 7 "path/filepath" 8 "testing" 9 10 kgit "tangled.org/core/knotserver/git" 11 "tangled.org/core/spindle/config" 12 "tangled.org/core/spindle/db" 13 "tangled.org/core/spindle/models" 14) 15 16func TestHasSkipCIPushOption(t *testing.T) { 17 tests := []struct { 18 name string 19 pushOptions []string 20 want bool 21 }{ 22 { 23 name: "skip-ci requests skip", 24 pushOptions: []string{"skip-ci"}, 25 want: true, 26 }, 27 { 28 name: "ci-skip requests skip", 29 pushOptions: []string{"ci-skip"}, 30 want: true, 31 }, 32 { 33 name: "unrelated ci options do not skip", 34 pushOptions: []string{"verbose-ci", "ci-verbose"}, 35 want: false, 36 }, 37 { 38 name: "empty options do not skip", 39 pushOptions: []string{}, 40 want: false, 41 }, 42 { 43 name: "nil options do not skip", 44 pushOptions: nil, 45 want: false, 46 }, 47 { 48 name: "mixed options skip when any skip option appears", 49 pushOptions: []string{"verbose-ci", "skip-ci", "ci-verbose"}, 50 want: true, 51 }, 52 } 53 54 for _, tt := range tests { 55 t.Run(tt.name, func(t *testing.T) { 56 got := kgit.HasSkipCIPushOption(tt.pushOptions) 57 if got != tt.want { 58 t.Fatalf("hasSkipCIPushOption(%v) = %v, want %v", tt.pushOptions, got, tt.want) 59 } 60 }) 61 } 62} 63 64func TestExecutorRoleBuildsMinimalSpindle(t *testing.T) { 65 ctx := context.Background() 66 dbPath := filepath.Join(t.TempDir(), "spindle.db") 67 d, err := db.Make(ctx, dbPath) 68 if err != nil { 69 t.Fatalf("db.Make() error = %v", err) 70 } 71 72 cfg := &config.Config{Role: config.RoleExecutor} 73 cfg.Server.DBPath = dbPath 74 cfg.Server.Hostname = "executor.test" 75 cfg.Server.Tap.Embed = true 76 cfg.ArtifactStores.Disk.Dir = t.TempDir() 77 cfg.Mill.ArtifactStore = "disk" 78 79 s, err := New(ctx, cfg, d, map[string]models.Engine{}) 80 if err != nil { 81 t.Fatalf("New() error = %v", err) 82 } 83 84 if s.jc != nil || s.tap != nil || s.e != nil || s.ks != nil || s.res != nil || s.vault != nil { 85 t.Fatal("executor role built coordinator-only spindle dependencies") 86 } 87 88 rr := httptest.NewRecorder() 89 req := httptest.NewRequest(http.MethodGet, "/", nil) 90 s.Router().ServeHTTP(rr, req) 91 if rr.Code != http.StatusOK { 92 t.Fatalf("root status = %d, want %d", rr.Code, http.StatusOK) 93 } 94 95 rr = httptest.NewRecorder() 96 req = httptest.NewRequest(http.MethodGet, "/xrpc/_health", nil) 97 s.Router().ServeHTTP(rr, req) 98 if rr.Code != http.StatusNotFound { 99 t.Fatalf("executor xrpc status = %d, want %d", rr.Code, http.StatusNotFound) 100 } 101}