MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / api_key

Function api_key

chirpstack/src/storage/api_key.rs:144–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142
143 #[tokio::test]
144 async fn api_key() {
145 let _guard = test::prepare().await;
146 let ak_admin = create_api_key(true, false).await;
147 let ak_tenant = create_api_key(false, true).await;
148
149 // get
150 let ak_get = get(&ak_admin.id).await.unwrap();
151 assert_eq!(ak_admin, ak_get);
152
153 // get count and list
154 let tests = vec![
155 FilterTest {
156 filters: Filters {
157 tenant_id: None,
158 is_admin: true,
159 },
160 keys: vec![&ak_admin],
161 count: 1,
162 limit: 10,
163 offset: 0,
164 },
165 FilterTest {
166 filters: Filters {
167 tenant_id: ak_tenant.tenant_id.map(|u| u.into()),
168 is_admin: false,
169 },
170 keys: vec![&ak_tenant],
171 count: 1,
172 limit: 10,
173 offset: 0,
174 },
175 ];
176
177 for tst in tests {
178 let count = get_count(&tst.filters).await.unwrap() as usize;
179 assert_eq!(tst.count, count);
180
181 let items = list(tst.limit, tst.offset, &tst.filters).await.unwrap();
182 assert_eq!(
183 tst.keys
184 .iter()
185 .map(|k| { k.id.to_string() })
186 .collect::<String>(),
187 items
188 .iter()
189 .map(|k| { k.id.to_string() })
190 .collect::<String>()
191 );
192 }
193
194 // delete
195 delete(&ak_admin.id).await.unwrap();
196 assert!(delete(&ak_admin.id).await.is_err());
197 }
198}

Callers

nothing calls this directly

Calls 7

prepareFunction · 0.85
create_api_keyFunction · 0.85
unwrapMethod · 0.80
getFunction · 0.70
get_countFunction · 0.70
listFunction · 0.70
deleteFunction · 0.70

Tested by

no test coverage detected