MCPcopy
hub / github.com/crowdsecurity/crowdsec / LoadTestConfig

Function LoadTestConfig

pkg/apiserver/apiserver_test.go:49–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47)
48
49func LoadTestConfig(t *testing.T) csconfig.Config {
50 config := csconfig.Config{}
51 maxAge := cstime.DurationWithDays(1 * time.Hour)
52 flushConfig := csconfig.FlushDBCfg{
53 MaxAge: maxAge,
54 }
55
56 tempDir, _ := os.MkdirTemp("", "crowdsec_tests")
57
58 t.Cleanup(func() { os.RemoveAll(tempDir) })
59
60 dbconfig := csconfig.DatabaseCfg{
61 Type: "sqlite",
62 DbPath: filepath.Join(tempDir, "ent"),
63 Flush: &flushConfig,
64 }
65 apiServerConfig := csconfig.LocalApiServerCfg{
66 ListenURI: "http://127.0.0.1:8080",
67 LogLevel: log.DebugLevel,
68 DbConfig: &dbconfig,
69 ProfilesPath: "./tests/profiles.yaml",
70 ConsoleConfig: &csconfig.ConsoleConfig{
71 ShareManualDecisions: new(bool),
72 ShareTaintedScenarios: new(bool),
73 ShareCustomScenarios: new(bool),
74 },
75 AutoRegister: &csconfig.LocalAPIAutoRegisterCfg{
76 Enable: new(true),
77 Token: validRegistrationToken,
78 AllowedRanges: []string{
79 "127.0.0.1/8",
80 "::1/128",
81 },
82 },
83 }
84
85 apiConfig := csconfig.APICfg{
86 Server: &apiServerConfig,
87 }
88
89 config.API = &apiConfig
90 err := config.API.Server.LoadProfiles()
91 require.NoError(t, err)
92
93 err = config.API.Server.LoadAutoRegister()
94 require.NoError(t, err)
95
96 return config
97}
98
99func LoadTestConfigForwardedFor(t *testing.T) csconfig.Config {
100 config := csconfig.Config{}

Callers 5

TestNewAPICFunction · 0.85
NewAPIServerFunction · 0.85
TestWithWrongDBConfigFunction · 0.85
TestWithWrongFlushConfigFunction · 0.85

Calls 2

LoadProfilesMethod · 0.80
LoadAutoRegisterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…