Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow api #580

Draft
wants to merge 10 commits into
base: zyppng-staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 36 additions & 21 deletions tests/media/CredentialManager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <zypp/Url.h>
#include <zypp/TmpPath.h>
#include <zypp-media/auth/CredentialFileReader>
#include <zypp-media/auth/CredentialManager>
#include <zypp-media/ng/auth/credentialmanager.h>

#include <zypp/PathInfo.h>
#include <zypp/ng/context.h>

using std::cout;
using std::endl;
using namespace zypp;
using namespace zypp::media;
using zyppng::media::CredentialManager;

inline void testGetCreds( CredentialManager & cm_r, const std::string & url_r,
const std::string & user_r = "",
Expand All @@ -34,19 +36,22 @@ inline void testGetCreds( CredentialManager & cm_r, const std::string & url_r,

BOOST_AUTO_TEST_CASE(read_cred_for_url)
{
CredManagerOptions opts;
auto ctx = zyppng::SyncContext::create();
ctx->initialize().unwrap ();

CredManagerSettings opts(ctx);
opts.globalCredFilePath = TESTS_SRC_DIR "/media/data/credentials.cat";
opts.userCredFilePath = Pathname();
CredentialManager cm( opts );
auto cm = CredentialManager::create( opts );

BOOST_CHECK_EQUAL( cm.credsGlobalSize(), 3 );
BOOST_CHECK_EQUAL( cm->credsGlobalSize(), 3 );

testGetCreds( cm, "https://drink.it/repo/roots", "ginger", "ale" );
testGetCreds( cm, "ftp://weprovidesoft.fr/download/opensuse/110", "agda", "ichard" );
testGetCreds( cm, "ftp://[email protected]/download/opensuse/110", "magda", "richard" );
testGetCreds( cm, "ftp://[email protected]/download/opensuse/110", "agda", "ichard" );
testGetCreds( cm, "ftp://[email protected]/download/opensuse/110" ); // NULL
testGetCreds( cm, "http://url.ok/but/not/creds" ); // NULL
testGetCreds( *cm, "https://drink.it/repo/roots", "ginger", "ale" );
testGetCreds( *cm, "ftp://weprovidesoft.fr/download/opensuse/110", "agda", "ichard" );
testGetCreds( *cm, "ftp://[email protected]/download/opensuse/110", "magda", "richard" );
testGetCreds( *cm, "ftp://[email protected]/download/opensuse/110", "agda", "ichard" );
testGetCreds( *cm, "ftp://[email protected]/download/opensuse/110" ); // NULL
testGetCreds( *cm, "http://url.ok/but/not/creds" ); // NULL
}

struct CredCollector
Expand All @@ -64,10 +69,15 @@ struct CredCollector

BOOST_AUTO_TEST_CASE(save_creds)
{
auto ctx = zyppng::SyncContext::create();
ctx->initialize().unwrap ();

CredManagerSettings opts(ctx);

filesystem::TmpDir tmp;
CredManagerOptions opts;
opts.globalCredFilePath = tmp / "fooha";
CredentialManager cm1(opts);

auto cm1 = CredentialManager::create(opts);

AuthData cr1("benson","absolute");
cr1.setUrl(Url("http://joooha.com"));
Expand All @@ -76,20 +86,20 @@ BOOST_AUTO_TEST_CASE(save_creds)
cr2.setUrl(Url("ftp://filesuck.org"));

// should create a new file
cm1.saveInGlobal(cr1);
cm1->saveInGlobal(cr1);

CredCollector collector;
CredentialFileReader( opts.globalCredFilePath, bind( &CredCollector::collect, &collector, _1 ) );
BOOST_CHECK_EQUAL( collector.creds.size(), 1 );

collector.creds.clear();
cm1.saveInGlobal(cr2);
cm1->saveInGlobal(cr2);
CredentialFileReader( opts.globalCredFilePath, bind( &CredCollector::collect, &collector, _1 ) );
BOOST_CHECK_EQUAL(collector.creds.size(), 2 );

collector.creds.clear();
// save the same creds again
cm1.saveInGlobal(cr2);
cm1->saveInGlobal(cr2);
CredentialFileReader( opts.globalCredFilePath, bind( &CredCollector::collect, &collector, _1 ) );
BOOST_CHECK_EQUAL(collector.creds.size(), 2 );

Expand All @@ -98,16 +108,21 @@ BOOST_AUTO_TEST_CASE(save_creds)

BOOST_AUTO_TEST_CASE(service_base_url)
{
auto ctx = zyppng::SyncContext::create();
ctx->initialize().unwrap ();

CredManagerSettings opts(ctx);

filesystem::TmpDir tmp;
CredManagerOptions opts;
opts.globalCredFilePath = tmp / "fooha";
CredentialManager cm( opts );

auto cm = CredentialManager::create( opts );

AuthData cred( "benson","absolute" );
cred.setUrl( Url( "http://joooha.com/service/path" ) );
cm.addGlobalCred( cred );
cm->addGlobalCred( cred );

testGetCreds( cm, "http://joooha.com/service/path/repo/repofoo", "benson", "absolute" );
testGetCreds( cm, "http://[email protected]/service/path/repo/repofoo", "benson", "absolute" );
testGetCreds( cm, "http://[email protected]/service/path/repo/repofoo" ); // NULL
testGetCreds( *cm, "http://joooha.com/service/path/repo/repofoo", "benson", "absolute" );
testGetCreds( *cm, "http://[email protected]/service/path/repo/repofoo", "benson", "absolute" );
testGetCreds( *cm, "http://[email protected]/service/path/repo/repofoo" ); // NULL
}
15 changes: 9 additions & 6 deletions tests/parser/RepoFileReader_test.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <sstream>
#include <string>
#include <zypp/parser/RepoFileReader.h>
#include <zypp/ng/context.h>
#include <zypp/ng/repoinfo.h>
#include <zypp/ng/parser/RepoFileReader.h>
#include <zypp/base/NonCopyable.h>

#include "TestSetup.h"

using std::stringstream;
using std::string;
using namespace zypp;

static std::string suse_repo = "[factory-oss]\n"
"name=factory-oss $releasever - $basearch\n"
Expand All @@ -29,13 +30,13 @@ static std::string suse_repo = "[factory-oss]\n"

struct RepoCollector : private base::NonCopyable
{
bool collect( const RepoInfo &repo )
bool collect( const zyppng::RepoInfo &repo )
{
repos.push_back(repo);
return true;
}

RepoInfoList repos;
zyppng::RepoInfoList repos;
};

// Must be the first test!
Expand All @@ -44,10 +45,12 @@ BOOST_AUTO_TEST_CASE(read_repo_file)
{
std::stringstream input(suse_repo);
RepoCollector collector;
parser::RepoFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );
zyppng::SyncContextRef ctx = zyppng::SyncContext::create ();
ctx->initialize().unwrap();
zyppng::parser::RepoFileReader parser( ctx, input, bind( &RepoCollector::collect, &collector, _1 ) );
BOOST_CHECK_EQUAL(1, collector.repos.size());

const RepoInfo & repo( collector.repos.front() );
const zyppng::RepoInfo & repo( collector.repos.front() );

BOOST_CHECK_EQUAL( 5, repo.baseUrlsSize() );
BOOST_CHECK_EQUAL( 5, repo.gpgKeyUrlsSize() );
Expand Down
18 changes: 12 additions & 6 deletions tests/parser/RepoindexFileReader_test.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include <sstream>
#include <string>
#include <zypp/Pathname.h>
#include <zypp/parser/RepoindexFileReader.h>
#include <zypp/base/NonCopyable.h>

#include <zypp/ng/parser/repoindexfilereader.h>
#include <zypp/ng/context.h>
#include <zypp/ng/repoinfo.h>

#include "TestSetup.h"

using std::stringstream;
Expand All @@ -21,13 +24,13 @@ static string service = "<repoindex arch=\"i386\" distver=\"11\">"

struct RepoCollector : private base::NonCopyable
{
bool collect( const RepoInfo &repo )
bool collect( const zyppng::RepoInfo &repo )
{
repos.push_back(repo);
return true;
}

RepoInfoList repos;
zyppng::RepoInfoList repos;
};

// Must be the first test!
Expand All @@ -36,11 +39,14 @@ BOOST_AUTO_TEST_CASE(read_index_file)
{
stringstream input(service);
RepoCollector collector;
parser::RepoindexFileReader parser( input, bind( &RepoCollector::collect, &collector, _1 ) );

auto ctx = zyppng::SyncContext::create();
ctx->initialize().unwrap();

zyppng::parser::RepoIndexFileReader parser( ctx, input, bind( &RepoCollector::collect, &collector, _1 ) );
BOOST_REQUIRE_EQUAL(3, collector.repos.size());

RepoInfo repo;
repo = collector.repos.front();
zyppng::RepoInfo repo = collector.repos.front();

BOOST_CHECK_EQUAL("Company's Foo", repo.name());
BOOST_CHECK_EQUAL("company-foo", repo.alias());
Expand Down
9 changes: 6 additions & 3 deletions tests/repo/MirrorList_test.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <iostream>
#include <vector>
#include <boost/test/unit_test.hpp>

#include "WebServer.h"

#include <zypp/repo/RepoMirrorList.h>
#include <zypp/ng/context.h>

using namespace zypp;
using namespace zypp::repo;
Expand All @@ -20,8 +20,11 @@ BOOST_AUTO_TEST_CASE(get_mirrorlist)
weburl1.setPathName("/metalink.xml");
weburl2.setPathName("/mirrors.txt");

RepoMirrorList rml1 (weburl1);
RepoMirrorList rml2 (weburl2);
auto ctx = zyppng::SyncContext::create();
ctx->initialize ().unwrap ();

RepoMirrorList rml1 ( ctx, weburl1 );
RepoMirrorList rml2 ( ctx, weburl2 );

BOOST_CHECK(rml1.getUrls().begin()->asString() == "http://ftp-stud.hs-esslingen.de/pub/fedora/linux/updates/13/x86_64/");
BOOST_CHECK(rml2.getUrls().begin()->asString() == "http://ftp-stud.hs-esslingen.de/pub/fedora/linux/updates/13/x86_64/");
Expand Down
18 changes: 9 additions & 9 deletions tests/repo/PluginServices_test.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <boost/test/unit_test.hpp>

#include <zypp/ZYppFactory.h>
#include <zypp/Url.h>
#include <zypp/PathInfo.h>
#include <zypp/TmpPath.h>
#include <zypp/ZConfig.h>
#include <zypp/repo/PluginServices.h>
#include <zypp/ServiceInfo.h>

#include <zypp/ng/context.h>
#include <zypp/ng/repo/pluginservices.h>
#include <zypp/ng/serviceinfo.h>

using std::cout;
using std::endl;
using std::string;
using namespace zypp;
using namespace zyppng;
using namespace boost::unit_test;
using namespace zypp::repo;
using namespace zyppng::repo;

#define DATADIR (Pathname(TESTS_SRC_DIR) + "/repo/yum/data")

Expand Down Expand Up @@ -46,7 +44,9 @@ BOOST_AUTO_TEST_CASE(plugin_services)
{
ServiceCollector::ServiceSet services;

PluginServices local("/space/tmp/services", ServiceCollector(services));
auto ctx = SyncContext::create();
ctx->initialize().unwrap();
PluginServices local(ctx, "/space/tmp/services", ServiceCollector(services));
}

// vim: set ts=2 sts=2 sw=2 ai et:
13 changes: 7 additions & 6 deletions tests/repo/susetags/Downloader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ BOOST_AUTO_TEST_CASE(susetags_download)
KeyRingTestReceiver keyring_callbacks;
keyring_callbacks.answerAcceptKey(KeyRingReport::KEY_TRUST_TEMPORARILY);


auto ctx = zyppng::SyncContext::create ();

Pathname p = DATADIR + "/stable-x86-subset";
RepoInfo repoinfo;
zyppng::RepoInfo repoinfo(ctx);
repoinfo.setAlias("testrepo");
repoinfo.setPath("/");

filesystem::TmpDir tmp;
Pathname localdir(tmp.path());


auto ctx = zyppng::SyncContext::create ();
auto res = ctx->initialize ()
| and_then( [&]() { return ctx->provider()->attachMedia( p.asDirUrl() , zyppng::ProvideMediaSpec() ); } )
| and_then( [&]( zyppng::SyncMediaHandle h ){
Expand Down Expand Up @@ -106,16 +107,16 @@ BOOST_AUTO_TEST_CASE(susetags_gz_download)
KeyRingTestReceiver keyring_callbacks;
keyring_callbacks.answerAcceptKey(KeyRingReport::KEY_TRUST_TEMPORARILY);

auto ctx = zyppng::SyncContext::create ();

Pathname p = DATADIR + "/stable-x86-subset-gz";

RepoInfo repoinfo;
zyppng::RepoInfo repoinfo(ctx);
repoinfo.setAlias("testrepo");
repoinfo.setPath("/");
filesystem::TmpDir tmp;

Pathname localdir(tmp.path());

auto ctx = zyppng::SyncContext::create ();
auto res = ctx->initialize ()
| and_then( [&]() { return ctx->provider()->attachMedia( p.asDirUrl() , zyppng::ProvideMediaSpec() ); } )
| and_then( [&]( zyppng::SyncMediaHandle h ){
Expand Down
5 changes: 3 additions & 2 deletions tests/repo/yum/YUMDownloader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ BOOST_AUTO_TEST_CASE(yum_download)
KeyRingTestReceiver keyring_callbacks;
keyring_callbacks.answerAcceptKey(KeyRingReport::KEY_TRUST_TEMPORARILY);

auto ctx = zyppng::SyncContext::create ();

Pathname p = DATADIR + "/ZCHUNK";
Url url(p.asDirUrl());
RepoInfo repoinfo;
zyppng::RepoInfo repoinfo(ctx);
repoinfo.setAlias("testrepo");
repoinfo.setPath("/");

filesystem::TmpDir tmp;
Pathname localdir(tmp.path());

auto ctx = zyppng::SyncContext::create ();
auto res = ctx->initialize ()
| and_then( [&]() { return ctx->provider()->attachMedia( p.asDirUrl() , zyppng::ProvideMediaSpec() ); } )
| and_then( [&]( zyppng::SyncMediaHandle h ){
Expand Down
1 change: 0 additions & 1 deletion tests/zypp/RepoManager_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <iostream>
#include <fstream>
#include <list>
Expand Down
8 changes: 4 additions & 4 deletions tests/zyppng/Pipelines_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ BOOST_AUTO_TEST_CASE( asyncToMixedPipelineWithIndirectAsyncCB )

auto op = zyppng::AsyncOpRef<std::string>(std::make_shared<DelayedValue<std::string>>("5"))
| &toSignedInt
| []( auto &&in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); }
| []( auto in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); }
| &toString
| [&]( auto && res ){
| [&]( auto res ){
BOOST_CHECK_EQUAL ( std::string("10") , res );
ev->quit ();
return res;
Expand All @@ -172,13 +172,13 @@ BOOST_AUTO_TEST_CASE( asyncToMixedPipelineWithIndirectAsyncCBInStdFunction )

const auto &makePipeline = [&](){

const std::function< AsyncOpRef<Int>( Int && ) > &addFiveAsync = []( auto &&in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); };
const std::function< AsyncOpRef<Int>( Int && ) > &addFiveAsync = []( auto in ){ in.value += 5; return std::make_shared<DelayedValue<Int>>(std::move(in)); };

return zyppng::AsyncOpRef<std::string>(std::make_shared<DelayedValue<std::string>>("5"))
| &toSignedInt
| addFiveAsync
| &toString
| [&]( auto && res ){
| [&]( auto res ){
BOOST_CHECK_EQUAL ( std::string("10") , res );
ev->quit ();
return res;
Expand Down
Loading