2017-09-21 22:26:06 +03:00
/*
2016-06-06 21:49:11 +03:00
* Copyright ( C ) 2016 Red Hat , Inc .
*
2018-01-30 22:26:26 +03:00
* SPDX - License - Identifier : LGPL - 2.0 +
*
2016-06-06 21:49:11 +03:00
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
2021-12-07 04:20:55 +03:00
* License along with this library . If not , see < https : //www.gnu.org/licenses/>.
2016-06-06 21:49:11 +03:00
*/
# include "config.h"
# include "libglnx.h"
2023-05-01 21:24:29 +03:00
# include <gio/gio.h>
2016-06-06 21:49:11 +03:00
# include <glib.h>
# include <stdlib.h>
# include <string.h>
# include "libostreetest.h"
2023-05-01 21:24:29 +03:00
typedef struct
{
2016-06-06 21:49:11 +03:00
OstreeRepo * repo ;
} TestData ;
static void
test_data_init ( TestData * td )
{
GError * local_error = NULL ;
GError * * error = & local_error ;
g_autofree char * http_address = NULL ;
g_autofree char * repo_url = NULL ;
td - > repo = ot_test_setup_repo ( NULL , error ) ;
if ( ! td - > repo )
goto out ;
2017-06-29 05:52:40 +03:00
if ( ! ot_test_run_libtest ( " setup_fake_remote_repo1 archive " , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
if ( ! g_file_get_contents ( " httpd-address " , & http_address , NULL , error ) )
goto out ;
2017-01-09 04:44:20 +03:00
g_strstrip ( http_address ) ;
2016-06-06 21:49:11 +03:00
repo_url = g_strconcat ( http_address , " /ostree/gnomerepo " , NULL ) ;
2023-05-01 21:24:29 +03:00
{
g_autoptr ( GVariantBuilder ) builder = g_variant_builder_new ( G_VARIANT_TYPE ( " a{sv} " ) ) ;
g_autoptr ( GVariant ) opts = NULL ;
2016-06-06 21:49:11 +03:00
2023-05-01 21:24:29 +03:00
g_variant_builder_add ( builder , " {s@v} " , " gpg-verify " ,
g_variant_new_variant ( g_variant_new_boolean ( FALSE ) ) ) ;
2016-06-06 21:49:11 +03:00
opts = g_variant_ref_sink ( g_variant_builder_end ( builder ) ) ;
2023-05-01 21:24:29 +03:00
if ( ! ostree_repo_remote_change ( td - > repo , NULL , OSTREE_REPO_REMOTE_CHANGE_ADD , " origin " ,
repo_url , opts , NULL , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
}
2023-05-01 21:24:29 +03:00
out :
2016-06-06 21:49:11 +03:00
g_assert_no_error ( local_error ) ;
}
static void
test_pull_multi_nochange ( gconstpointer data )
{
GError * local_error = NULL ;
GError * * error = & local_error ;
2023-05-01 21:24:29 +03:00
TestData * td = ( void * ) data ;
2016-06-06 21:49:11 +03:00
char * refs [ ] = { " main " , NULL } ;
2023-05-01 21:24:29 +03:00
if ( ! ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & refs , 0 , NULL , NULL , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
2023-05-01 21:24:29 +03:00
if ( ! ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & refs , 0 , NULL , NULL , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
2023-05-01 21:24:29 +03:00
if ( ! ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & refs , 0 , NULL , NULL , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
2023-02-08 00:48:15 +03:00
2023-05-01 21:24:29 +03:00
out :
2016-06-06 21:49:11 +03:00
g_assert_no_error ( local_error ) ;
}
static void
test_pull_multi_error_then_ok ( gconstpointer data )
{
GError * local_error = NULL ;
GError * * error = & local_error ;
2023-02-08 00:48:15 +03:00
2023-05-01 21:24:29 +03:00
TestData * td = ( void * ) data ;
2016-06-06 21:49:11 +03:00
char * ok_refs [ ] = { " main " , NULL } ;
char * bad_refs [ ] = { " nosuchbranch " , NULL } ;
for ( guint i = 0 ; i < 3 ; i + + )
{
2023-05-01 21:24:29 +03:00
g_autoptr ( GError ) tmp_error = NULL ;
if ( ! ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & ok_refs , 0 , NULL , NULL , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
2023-05-01 21:24:29 +03:00
if ( ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & bad_refs , 0 , NULL , NULL , & tmp_error ) )
2016-06-06 21:49:11 +03:00
g_assert_not_reached ( ) ;
g_clear_error ( & tmp_error ) ;
2023-05-01 21:24:29 +03:00
if ( ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & bad_refs , 0 , NULL , NULL , & tmp_error ) )
2016-06-06 21:49:11 +03:00
g_assert_not_reached ( ) ;
g_clear_error ( & tmp_error ) ;
2023-05-01 21:24:29 +03:00
if ( ! ostree_repo_pull ( td - > repo , " origin " , ( char * * ) & ok_refs , 0 , NULL , NULL , error ) )
2016-06-06 21:49:11 +03:00
goto out ;
}
2023-02-08 00:48:15 +03:00
2023-05-01 21:24:29 +03:00
out :
2016-06-06 21:49:11 +03:00
g_assert_no_error ( local_error ) ;
}
2023-05-01 21:24:29 +03:00
int
main ( int argc , char * * argv )
2016-06-06 21:49:11 +03:00
{
2023-05-01 21:24:29 +03:00
TestData td = {
NULL ,
} ;
2016-06-06 21:49:11 +03:00
int r ;
test_data_init ( & td ) ;
g_test_init ( & argc , & argv , NULL ) ;
g_test_add_data_func ( " /test-pull-c/multi-nochange " , & td , test_pull_multi_nochange ) ;
g_test_add_data_func ( " /test-pull-c/multi-ok-error-repeat " , & td , test_pull_multi_error_then_ok ) ;
2023-05-01 21:24:29 +03:00
r = g_test_run ( ) ;
2016-11-29 06:03:53 +03:00
g_clear_object ( & td . repo ) ;
2016-06-06 21:49:11 +03:00
return r ;
}