MCPcopy
hub / github.com/bettercap/bettercap / TestNewRestAPI

Function TestNewRestAPI

modules/api_rest/api_rest_test.go:31–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestNewRestAPI(t *testing.T) {
32 s := createMockSession(t)
33 mod := NewRestAPI(s)
34
35 if mod == nil {
36 t.Fatal("NewRestAPI returned nil")
37 }
38
39 if mod.Name() != "api.rest" {
40 t.Errorf("Expected name 'api.rest', got '%s'", mod.Name())
41 }
42
43 if mod.Author() != "Simone Margaritelli <evilsocket@gmail.com>" {
44 t.Errorf("Unexpected author: %s", mod.Author())
45 }
46
47 if mod.Description() == "" {
48 t.Error("Empty description")
49 }
50
51 // Check handlers
52 handlers := mod.Handlers()
53 expectedHandlers := []string{
54 "api.rest on",
55 "api.rest off",
56 "api.rest.record off",
57 "api.rest.record FILENAME",
58 "api.rest.replay off",
59 "api.rest.replay FILENAME",
60 }
61
62 if len(handlers) != len(expectedHandlers) {
63 t.Errorf("Expected %d handlers, got %d", len(expectedHandlers), len(handlers))
64 }
65
66 handlerNames := make(map[string]bool)
67 for _, h := range handlers {
68 handlerNames[h.Name] = true
69 }
70
71 for _, expected := range expectedHandlers {
72 if !handlerNames[expected] {
73 t.Errorf("Handler '%s' not found", expected)
74 }
75 }
76
77 // Check initial state
78 if mod.recording {
79 t.Error("Should not be recording initially")
80 }
81 if mod.replaying {
82 t.Error("Should not be replaying initially")
83 }
84 if mod.useWebsocket {
85 t.Error("Should not use websocket by default")
86 }
87 if mod.allowOrigin != "*" {
88 t.Errorf("Expected default allowOrigin '*', got '%s'", mod.allowOrigin)

Callers

nothing calls this directly

Calls 8

NameMethod · 0.95
AuthorMethod · 0.95
DescriptionMethod · 0.95
NewRestAPIFunction · 0.85
createMockSessionFunction · 0.70
HandlersMethod · 0.65
FatalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected