(t *testing.T)
| 135 | } |
| 136 | |
| 137 | func TestLoadAPIServer(t *testing.T) { |
| 138 | tmpLAPI := &LocalApiServerCfg{ |
| 139 | ProfilesPath: "./testdata/profiles.yaml", |
| 140 | } |
| 141 | err := tmpLAPI.LoadProfiles() |
| 142 | require.NoError(t, err) |
| 143 | |
| 144 | logLevel := log.InfoLevel |
| 145 | config := &Config{} |
| 146 | fcontent, err := os.ReadFile("./testdata/config.yaml") |
| 147 | require.NoError(t, err) |
| 148 | |
| 149 | configData := os.ExpandEnv(string(fcontent)) |
| 150 | |
| 151 | dec := yaml.NewDecoder(strings.NewReader(configData)) |
| 152 | dec.KnownFields(true) |
| 153 | |
| 154 | err = dec.Decode(&config) |
| 155 | require.NoError(t, err) |
| 156 | |
| 157 | tests := []struct { |
| 158 | name string |
| 159 | input *Config |
| 160 | expected *LocalApiServerCfg |
| 161 | expectedErr string |
| 162 | }{ |
| 163 | { |
| 164 | name: "basic valid configuration", |
| 165 | input: &Config{ |
| 166 | Self: []byte(configData), |
| 167 | API: &APICfg{ |
| 168 | Server: &LocalApiServerCfg{ |
| 169 | ListenURI: "http://crowdsec.api", |
| 170 | OnlineClient: &OnlineApiClientCfg{ |
| 171 | CredentialsFilePath: "./testdata/online-api-secrets.yaml", |
| 172 | }, |
| 173 | ProfilesPath: "./testdata/profiles.yaml", |
| 174 | PapiLogLevel: logLevel, |
| 175 | }, |
| 176 | }, |
| 177 | DbConfig: &DatabaseCfg{ |
| 178 | Type: "sqlite", |
| 179 | DbPath: "./testdata/test.db", |
| 180 | }, |
| 181 | Common: &CommonCfg{ |
| 182 | LogConfig: LogConfig{ |
| 183 | LogDir: "./testdata", |
| 184 | LogMedia: "stdout", |
| 185 | }, |
| 186 | }, |
| 187 | DisableAPI: false, |
| 188 | }, |
| 189 | expected: &LocalApiServerCfg{ |
| 190 | Enable: new(true), |
| 191 | ListenURI: "http://crowdsec.api", |
| 192 | TLS: nil, |
| 193 | DbConfig: &DatabaseCfg{ |
| 194 | DbPath: "./testdata/test.db", |
nothing calls this directly
no test coverage detected
searching dependent graphs…