@@ -15,6 +15,13 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
1515 int prio = 12345 ;
1616 bool wantMassQuery = true ;
1717
18+ auto mkFields = [](bool wantMassQuery, int prio) {
19+ return std::map<std::string, std::string>{
20+ {" WantMassQuery" , wantMassQuery ? " 1" : " 0" },
21+ {" Priority" , std::to_string (prio)},
22+ };
23+ };
24+
1825 auto tmpDir = createTempDir ();
1926 AutoDelete delTmpDir (tmpDir);
2027 auto dbPath (tmpDir / " test-narinfo-disk-cache.sqlite" );
@@ -30,22 +37,20 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
3037
3138 // Set up "background noise" and check that different caches receive different ids
3239 {
33- auto bc1 =
34- cache->createCache (" https://bar" , " /nix/storedir" , {.wantMassQuery = wantMassQuery, .priority = prio});
35- auto bc2 = cache->createCache (" https://xyz" , " /nix/storedir" , {.priority = 12 });
40+ auto bc1 = cache->createCache (" https://bar" , " /nix/storedir" , {.fields = mkFields (wantMassQuery, prio)});
41+ auto bc2 = cache->createCache (" https://xyz" , " /nix/storedir" , {.fields = mkFields (false , 12 )});
3642 ASSERT_NE (bc1, bc2);
3743 barId = bc1;
3844 }
3945
4046 // Check that the fields are saved and returned correctly. This does not test
4147 // the select statement yet, because of in-memory caching.
42- savedId = cache->createCache (" http://foo" , " /nix/storedir" , {.wantMassQuery = wantMassQuery, . priority = prio});
48+ savedId = cache->createCache (" http://foo" , " /nix/storedir" , {.fields = mkFields ( wantMassQuery, prio) });
4349 ;
4450 {
4551 auto r = cache->upToDateCacheExists (" http://foo" );
4652 ASSERT_TRUE (r);
47- ASSERT_EQ (r->priority , prio);
48- ASSERT_EQ (r->wantMassQuery , wantMassQuery);
53+ ASSERT_EQ (r->fields , mkFields (wantMassQuery, prio));
4954 ASSERT_EQ (savedId, r->id );
5055 }
5156
@@ -68,8 +73,7 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
6873 {
6974 auto r = cache->upToDateCacheExists (" http://foo" );
7075 ASSERT_TRUE (r);
71- ASSERT_EQ (r->priority , prio);
72- ASSERT_EQ (r->wantMassQuery , wantMassQuery);
76+ ASSERT_EQ (r->fields , mkFields (wantMassQuery, prio));
7377 }
7478 }
7579
@@ -85,13 +89,12 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
8589 }
8690
8791 // "Update", same data, check that the id number is reused
88- cache2->createCache (" http://foo" , " /nix/storedir" , {.wantMassQuery = wantMassQuery, . priority = prio});
92+ cache2->createCache (" http://foo" , " /nix/storedir" , {.fields = mkFields ( wantMassQuery, prio) });
8993
9094 {
9195 auto r = cache2->upToDateCacheExists (" http://foo" );
9296 ASSERT_TRUE (r);
93- ASSERT_EQ (r->priority , prio);
94- ASSERT_EQ (r->wantMassQuery , wantMassQuery);
97+ ASSERT_EQ (r->fields , mkFields (wantMassQuery, prio));
9598 ASSERT_EQ (r->id , savedId);
9699 }
97100
@@ -108,11 +111,9 @@ TEST(NarInfoDiskCacheImpl, create_and_read)
108111 auto r0 = cache2->upToDateCacheExists (" https://bar" );
109112 ASSERT_FALSE (r0);
110113
111- cache2->createCache (
112- " https://bar" , " /nix/storedir" , {.wantMassQuery = !wantMassQuery, .priority = prio + 10 });
114+ cache2->createCache (" https://bar" , " /nix/storedir" , {.fields = mkFields (!wantMassQuery, prio + 10 )});
113115 auto r = cache2->upToDateCacheExists (" https://bar" );
114- ASSERT_EQ (r->wantMassQuery , !wantMassQuery);
115- ASSERT_EQ (r->priority , prio + 10 );
116+ ASSERT_EQ (r->fields , mkFields (!wantMassQuery, prio + 10 ));
116117 ASSERT_EQ (r->id , barId);
117118 }
118119
0 commit comments