fa60894010ab970ae92f9d7e3a2d0a94b3da7a27
[platform/upstream/libzypp.git] / tests / repo / yum / YUMDownloader_test.cc
1 #include <stdio.h>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 #include <list>
6 #include <boost/test/auto_unit_test.hpp>
7 #include <solv/solvversion.h>
8
9 #include "zypp/base/Logger.h"
10 #include "zypp/Url.h"
11 #include "zypp/PathInfo.h"
12 #include "zypp/TmpPath.h"
13 #include "zypp/repo/yum/Downloader.h"
14 #include "tests/zypp/KeyRingTestReceiver.h"
15
16 using std::cout;
17 using std::endl;
18 using namespace zypp;
19 using namespace boost::unit_test;
20
21 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/repo/yum/data")
22
23 BOOST_AUTO_TEST_CASE(yum_download)
24 {
25   KeyRingTestReceiver keyring_callbacks;
26   keyring_callbacks.answerAcceptKey(KeyRingReport::KEY_TRUST_TEMPORARILY);
27
28   Pathname p = DATADIR + "/ZCHUNK";
29   Url url(p.asDirUrl());
30   MediaSetAccess media(url);
31   RepoInfo repoinfo;
32   repoinfo.setAlias("testrepo");
33   repoinfo.setPath("/");
34   repo::yum::Downloader yum(repoinfo);
35   filesystem::TmpDir tmp;
36
37   Pathname localdir(tmp.path());
38
39   yum.download(media, localdir);
40
41 #ifdef LIBSOLVEXT_FEATURE_ZSTD_COMPRESSION
42     const bool zchunk = true;
43 #else
44     const bool zchunk = false;
45 #endif
46   std::map<std::string,bool> files {
47     { "filelists.xml.gz",       false&&!zchunk },
48     { "filelists.xml.zck",      false&&zchunk },
49     { "other.xml.gz",           false&&!zchunk },
50     { "other.xml.zck",          false&&zchunk },
51     { "patterns.xml.gz",        true },
52     { "primary.xml.gz",         !zchunk },
53     { "primary.xml.zck",        zchunk },
54     { "repomd.xml",             true },
55     { "repomd.xml.asc",         true },
56     { "repomd.xml.key",         true },
57   };
58
59   for ( const auto & el : files )
60   {
61     Pathname stem { "/repodata/"+el.first };
62     bool downloaded { PathInfo(localdir/stem).isExist() };
63     BOOST_CHECK_MESSAGE( downloaded == el.second, std::string(el.second?"missing ":"unexpected ")+stem );
64   }
65
66 }
67
68 // vim: set ts=2 sts=2 sw=2 ai et: