Blame tests/test-repo-finder-config.c

rpm-build 0fba15
/*
rpm-build 0fba15
 * Copyright © 2017 Endless Mobile, Inc.
rpm-build 0fba15
 *
rpm-build 0fba15
 * SPDX-License-Identifier: LGPL-2.0+
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is free software; you can redistribute it and/or
rpm-build 0fba15
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0fba15
 * License as published by the Free Software Foundation; either
rpm-build 0fba15
 * version 2 of the License, or (at your option) any later version.
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is distributed in the hope that it will be useful,
rpm-build 0fba15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0fba15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0fba15
 * Lesser General Public License for more details.
rpm-build 0fba15
 *
rpm-build 0fba15
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0fba15
 * License along with this library; if not, write to the
rpm-build 0fba15
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rpm-build 0fba15
 * Boston, MA 02111-1307, USA.
rpm-build 0fba15
 *
rpm-build 0fba15
 * Authors:
rpm-build 0fba15
 *  - Philip Withnall <withnall@endlessm.com>
rpm-build 0fba15
 */
rpm-build 0fba15
rpm-build 0fba15
#include "config.h"
rpm-build 0fba15
rpm-build 0fba15
#include <gio/gio.h>
rpm-build 0fba15
#include <glib.h>
rpm-build 0fba15
#include <glib-object.h>
rpm-build 0fba15
#include <libglnx.h>
rpm-build 0fba15
#include <locale.h>
rpm-build 0fba15
#include <string.h>
rpm-build 0fba15
rpm-build 0fba15
#include "libostreetest.h"
rpm-build 0fba15
#include "ostree-autocleanups.h"
rpm-build 0fba15
#include "ostree-repo-finder.h"
rpm-build 0fba15
#include "ostree-repo-finder-config.h"
rpm-build 0fba15
rpm-build 0fba15
/* Test fixture. Creates a temporary directory. */
rpm-build 0fba15
typedef struct
rpm-build 0fba15
{
rpm-build 0fba15
  OstreeRepo *parent_repo;  /* owned */
rpm-build 0fba15
  GLnxTmpDir tmpdir; /* owned */
rpm-build 0fba15
  GFile *working_dir;  /* owned */
rpm-build 0fba15
} Fixture;
rpm-build 0fba15
rpm-build 0fba15
static void
rpm-build 0fba15
setup (Fixture       *fixture,
rpm-build 0fba15
       gconstpointer  test_data)
rpm-build 0fba15
{
rpm-build 0fba15
  g_autoptr(GError) error = NULL;
rpm-build 0fba15
rpm-build 0fba15
  (void)glnx_mkdtemp ("test-repo-finder-config-XXXXXX", 0700, &fixture->tmpdir, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
  g_test_message ("Using temporary directory: %s", fixture->tmpdir.path);
rpm-build 0fba15
rpm-build 0fba15
  glnx_shutil_mkdir_p_at (fixture->tmpdir.fd, "repo", 0700, NULL, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
  fixture->working_dir = g_file_new_for_path (fixture->tmpdir.path);
rpm-build 0fba15
rpm-build 0fba15
  fixture->parent_repo = ot_test_setup_repo (NULL, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static void
rpm-build 0fba15
teardown (Fixture       *fixture,
rpm-build 0fba15
          gconstpointer  test_data)
rpm-build 0fba15
{
rpm-build 0fba15
  /* Recursively remove the temporary directory. */
rpm-build 0fba15
  (void)glnx_tmpdir_delete (&fixture->tmpdir, NULL, NULL);
rpm-build 0fba15
rpm-build 0fba15
  /* The repo also needs its source files to be removed. This is the inverse
rpm-build 0fba15
   * of setup_test_repository() in libtest.sh. */
rpm-build 0fba15
  int parent_repo_dfd = ostree_repo_get_dfd (fixture->parent_repo);
rpm-build 0fba15
  glnx_shutil_rm_rf_at (parent_repo_dfd, "../files", NULL, NULL);
rpm-build 0fba15
  glnx_shutil_rm_rf_at (parent_repo_dfd, "../repo", NULL, NULL);
rpm-build 0fba15
rpm-build 0fba15
  g_clear_object (&fixture->working_dir);
rpm-build 0fba15
  g_clear_object (&fixture->parent_repo);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
/* Test the object constructor works at a basic level. */
rpm-build 0fba15
static void
rpm-build 0fba15
test_repo_finder_config_init (void)
rpm-build 0fba15
{
rpm-build 0fba15
  g_autoptr(OstreeRepoFinderConfig) finder = NULL;
rpm-build 0fba15
rpm-build 0fba15
  /* Default everything. */
rpm-build 0fba15
  finder = ostree_repo_finder_config_new ();
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static void
rpm-build 0fba15
result_cb (GObject      *source_object,
rpm-build 0fba15
           GAsyncResult *result,
rpm-build 0fba15
           gpointer      user_data)
rpm-build 0fba15
{
rpm-build 0fba15
  GAsyncResult **result_out = user_data;
rpm-build 0fba15
  *result_out = g_object_ref (result);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
/* Test that no remotes are found if there are no config files in the refs
rpm-build 0fba15
 * directory. */
rpm-build 0fba15
static void
rpm-build 0fba15
test_repo_finder_config_no_configs (Fixture       *fixture,
rpm-build 0fba15
                                    gconstpointer  test_data)
rpm-build 0fba15
{
rpm-build 0fba15
  g_autoptr(OstreeRepoFinderConfig) finder = NULL;
rpm-build 0fba15
  g_autoptr(GMainContext) context = NULL;
rpm-build 0fba15
  g_autoptr(GAsyncResult) result = NULL;
rpm-build 0fba15
  g_autoptr(GPtrArray) results = NULL;  /* (element-type OstreeRepoFinderResult) */
rpm-build 0fba15
  g_autoptr(GError) error = NULL;
rpm-build 0fba15
  const OstreeCollectionRef ref1 = { "org.example.Os", "exampleos/x86_64/standard" };
rpm-build 0fba15
  const OstreeCollectionRef ref2 = { "org.example.Os", "exampleos/x86_64/buildmaster/standard" };
rpm-build 0fba15
  const OstreeCollectionRef * const refs[] = { &ref1, &ref2, NULL };
rpm-build 0fba15
rpm-build 0fba15
  context = g_main_context_new ();
rpm-build 0fba15
  g_main_context_push_thread_default (context);
rpm-build 0fba15
rpm-build 0fba15
  finder = ostree_repo_finder_config_new ();
rpm-build 0fba15
rpm-build 0fba15
  ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs,
rpm-build 0fba15
                                    fixture->parent_repo, NULL, result_cb, &result);
rpm-build 0fba15
rpm-build 0fba15
  while (result == NULL)
rpm-build 0fba15
    g_main_context_iteration (context, TRUE);
rpm-build 0fba15
rpm-build 0fba15
  results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder),
rpm-build 0fba15
                                               result, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
  g_assert_nonnull (results);
rpm-build 0fba15
  g_assert_cmpuint (results->len, ==, 0);
rpm-build 0fba15
rpm-build 0fba15
  g_main_context_pop_thread_default (context);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
/* Add configuration for a remote named @remote_name, at @remote_uri, with a
rpm-build 0fba15
 * remote collection ID of @collection_id, to the given @repo. */
rpm-build 0fba15
static void
rpm-build 0fba15
assert_create_remote_config (OstreeRepo  *repo,
rpm-build 0fba15
                             const gchar *remote_name,
rpm-build 0fba15
                             const gchar *remote_uri,
rpm-build 0fba15
                             const gchar *collection_id)
rpm-build 0fba15
{
rpm-build 0fba15
  g_autoptr(GError) error = NULL;
rpm-build 0fba15
  g_autoptr(GVariant) options = NULL;
rpm-build 0fba15
rpm-build 0fba15
  if (collection_id != NULL)
rpm-build 0fba15
    options = g_variant_new_parsed ("@a{sv} { 'collection-id': <%s> }",
rpm-build 0fba15
                                    collection_id);
rpm-build 0fba15
rpm-build 0fba15
  ostree_repo_remote_add (repo, remote_name, remote_uri, options, NULL, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static gchar *assert_create_remote (Fixture     *fixture,
rpm-build 0fba15
                                    const gchar *collection_id,
rpm-build 0fba15
                                    ...) G_GNUC_NULL_TERMINATED;
rpm-build 0fba15
rpm-build 0fba15
/* Create a new repository in a temporary directory with its collection ID set
rpm-build 0fba15
 * to @collection_id, and containing the refs given in @... (which must be
rpm-build 0fba15
 * %NULL-terminated). Return the `file://` URI of the new repository. */
rpm-build 0fba15
static gchar *
rpm-build 0fba15
assert_create_remote (Fixture     *fixture,
rpm-build 0fba15
                      const gchar *collection_id,
rpm-build 0fba15
                      ...)
rpm-build 0fba15
{
rpm-build 0fba15
  va_list args;
rpm-build 0fba15
  g_autoptr(GError) error = NULL;
rpm-build 0fba15
  const gchar *repo_name = (collection_id != NULL) ? collection_id : "no-collection";
rpm-build 0fba15
rpm-build 0fba15
  glnx_shutil_mkdir_p_at (fixture->tmpdir.fd, repo_name, 0700, NULL, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
  g_autoptr(GFile) repo_path = g_file_get_child (fixture->working_dir, repo_name);
rpm-build 0fba15
  g_autoptr(OstreeRepo) repo = ostree_repo_new (repo_path);
rpm-build 0fba15
  ostree_repo_set_collection_id (repo, collection_id, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
  ostree_repo_create (repo, OSTREE_REPO_MODE_ARCHIVE, NULL, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
  /* Set up the refs from @.... */
rpm-build 0fba15
  va_start (args, collection_id);
rpm-build 0fba15
rpm-build 0fba15
  for (const gchar *ref_name = va_arg (args, const gchar *);
rpm-build 0fba15
       ref_name != NULL;
rpm-build 0fba15
       ref_name = va_arg (args, const gchar *))
rpm-build 0fba15
    {
rpm-build 0fba15
      OstreeCollectionRef collection_ref = { (gchar *) collection_id, (gchar *) ref_name };
rpm-build 0fba15
      g_autofree gchar *checksum = NULL;
rpm-build 0fba15
      g_autoptr(OstreeMutableTree) mtree = NULL;
rpm-build 0fba15
      g_autoptr(OstreeRepoFile) repo_file = NULL;
rpm-build 0fba15
rpm-build 0fba15
      mtree = ostree_mutable_tree_new ();
rpm-build 0fba15
      ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, ".", mtree, NULL, NULL, &error);
rpm-build 0fba15
      g_assert_no_error (error);
rpm-build 0fba15
      ostree_repo_write_mtree (repo, mtree, (GFile **) &repo_file, NULL, &error);
rpm-build 0fba15
      g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
      ostree_repo_write_commit (repo, NULL  /* no parent */, ref_name, ref_name,
rpm-build 0fba15
                                NULL  /* no metadata */, repo_file, &checksum,
rpm-build 0fba15
                                NULL, &error);
rpm-build 0fba15
      g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
      if (collection_id != NULL)
rpm-build 0fba15
        ostree_repo_set_collection_ref_immediate (repo, &collection_ref, checksum, NULL, &error);
rpm-build 0fba15
      else
rpm-build 0fba15
        ostree_repo_set_ref_immediate (repo, NULL, ref_name, checksum, NULL, &error);
rpm-build 0fba15
      g_assert_no_error (error);
rpm-build 0fba15
    }
rpm-build 0fba15
rpm-build 0fba15
  va_end (args);
rpm-build 0fba15
rpm-build 0fba15
  /* Update the summary. */
rpm-build 0fba15
  ostree_repo_regenerate_summary (repo, NULL  /* no metadata */, NULL, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
rpm-build 0fba15
  return g_file_get_uri (repo_path);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
/* Test resolving the refs against a collection of config files, which contain
rpm-build 0fba15
 * valid, invalid or duplicate repo information. */
rpm-build 0fba15
static void
rpm-build 0fba15
test_repo_finder_config_mixed_configs (Fixture       *fixture,
rpm-build 0fba15
                                       gconstpointer  test_data)
rpm-build 0fba15
{
rpm-build 0fba15
  g_autoptr(OstreeRepoFinderConfig) finder = NULL;
rpm-build 0fba15
  g_autoptr(GMainContext) context = NULL;
rpm-build 0fba15
  g_autoptr(GAsyncResult) result = NULL;
rpm-build 0fba15
  g_autoptr(GPtrArray) results = NULL;  /* (element-type OstreeRepoFinderResult) */
rpm-build 0fba15
  g_autoptr(GError) error = NULL;
rpm-build 0fba15
  gsize i;
rpm-build 0fba15
  const OstreeCollectionRef ref0 = { "org.example.Collection0", "exampleos/x86_64/ref0" };
rpm-build 0fba15
  const OstreeCollectionRef ref1 = { "org.example.Collection0", "exampleos/x86_64/ref1" };
rpm-build 0fba15
  const OstreeCollectionRef ref2 = { "org.example.Collection1", "exampleos/x86_64/ref1" };
rpm-build 0fba15
  const OstreeCollectionRef ref3 = { "org.example.Collection1", "exampleos/x86_64/ref2" };
rpm-build 0fba15
  const OstreeCollectionRef ref4 = { "org.example.Collection2", "exampleos/x86_64/ref3" };
rpm-build 0fba15
  const OstreeCollectionRef * const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, NULL };
rpm-build 0fba15
rpm-build 0fba15
  context = g_main_context_new ();
rpm-build 0fba15
  g_main_context_push_thread_default (context);
rpm-build 0fba15
rpm-build 0fba15
  /* Put together various ref configuration files. */
rpm-build 0fba15
  g_autofree gchar *collection0_uri = assert_create_remote (fixture, "org.example.Collection0",
rpm-build 0fba15
                                                            "exampleos/x86_64/ref0",
rpm-build 0fba15
                                                            "exampleos/x86_64/ref1",
rpm-build 0fba15
                                                            NULL);
rpm-build 0fba15
  g_autofree gchar *collection1_uri = assert_create_remote (fixture, "org.example.Collection1",
rpm-build 0fba15
                                                            "exampleos/x86_64/ref2",
rpm-build 0fba15
                                                            NULL);
rpm-build 0fba15
  g_autofree gchar *no_collection_uri = assert_create_remote (fixture, NULL,
rpm-build 0fba15
                                                              "exampleos/x86_64/ref3",
rpm-build 0fba15
                                                              NULL);
rpm-build 0fba15
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote0", collection0_uri, "org.example.Collection0");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote1", collection1_uri, "org.example.Collection1");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote0-copy", collection0_uri, "org.example.Collection0");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote1-bad-copy", collection1_uri, "org.example.NotCollection1");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote2", no_collection_uri, NULL);
rpm-build 0fba15
rpm-build 0fba15
  finder = ostree_repo_finder_config_new ();
rpm-build 0fba15
rpm-build 0fba15
  /* Resolve the refs. */
rpm-build 0fba15
  ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs,
rpm-build 0fba15
                                    fixture->parent_repo, NULL, result_cb, &result);
rpm-build 0fba15
rpm-build 0fba15
  while (result == NULL)
rpm-build 0fba15
    g_main_context_iteration (context, TRUE);
rpm-build 0fba15
rpm-build 0fba15
  results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder),
rpm-build 0fba15
                                               result, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
  g_assert_nonnull (results);
rpm-build 0fba15
  g_assert_cmpuint (results->len, ==, 3);
rpm-build 0fba15
rpm-build 0fba15
  /* Check that the results are correct: the invalid refs should have been
rpm-build 0fba15
   * ignored, and the valid results canonicalised and deduplicated. */
rpm-build 0fba15
  for (i = 0; i < results->len; i++)
rpm-build 0fba15
    {
rpm-build 0fba15
      const OstreeRepoFinderResult *result = g_ptr_array_index (results, i);
rpm-build 0fba15
rpm-build 0fba15
      if (g_strcmp0 (ostree_remote_get_name (result->remote), "remote0") == 0 ||
rpm-build 0fba15
          g_strcmp0 (ostree_remote_get_name (result->remote), "remote0-copy") == 0)
rpm-build 0fba15
        {
rpm-build 0fba15
          g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 2);
rpm-build 0fba15
          g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref0));
rpm-build 0fba15
          g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref1));
rpm-build 0fba15
          g_assert_cmpstr (ostree_remote_get_url (result->remote), ==, collection0_uri);
rpm-build 0fba15
        }
rpm-build 0fba15
      else if (g_strcmp0 (ostree_remote_get_name (result->remote), "remote1") == 0)
rpm-build 0fba15
        {
rpm-build 0fba15
          g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 1);
rpm-build 0fba15
          g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref3));
rpm-build 0fba15
          g_assert_cmpstr (ostree_remote_get_url (result->remote), ==, collection1_uri);
rpm-build 0fba15
        }
rpm-build 0fba15
      else
rpm-build 0fba15
        {
rpm-build 0fba15
          g_assert_not_reached ();
rpm-build 0fba15
        }
rpm-build 0fba15
    }
rpm-build 0fba15
rpm-build 0fba15
  g_main_context_pop_thread_default (context);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
/* Test that using ostree_repo_find_remotes_async() works too.*/
rpm-build 0fba15
static void
rpm-build 0fba15
test_repo_finder_config_find_remotes (Fixture       *fixture,
rpm-build 0fba15
                                      gconstpointer  test_data)
rpm-build 0fba15
{
rpm-build 0fba15
  g_autoptr(GMainContext) context = NULL;
rpm-build 0fba15
  g_autoptr(GAsyncResult) result = NULL;
rpm-build 0fba15
  g_auto(OstreeRepoFinderResultv) results = NULL;
rpm-build 0fba15
  g_autoptr(GError) error = NULL;
rpm-build 0fba15
  gsize i;
rpm-build 0fba15
  const OstreeCollectionRef ref0 = { "org.example.Collection0", "exampleos/x86_64/ref0" };
rpm-build 0fba15
  const OstreeCollectionRef ref1 = { "org.example.Collection0", "exampleos/x86_64/ref1" };
rpm-build 0fba15
  const OstreeCollectionRef ref2 = { "org.example.Collection1", "exampleos/x86_64/ref1" };
rpm-build 0fba15
  const OstreeCollectionRef ref3 = { "org.example.Collection1", "exampleos/x86_64/ref2" };
rpm-build 0fba15
  const OstreeCollectionRef ref4 = { "org.example.Collection2", "exampleos/x86_64/ref3" };
rpm-build 0fba15
  const OstreeCollectionRef * const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, NULL };
rpm-build 0fba15
  OstreeRepoFinder *finders[2] = {NULL, };
rpm-build 0fba15
rpm-build 0fba15
  context = g_main_context_new ();
rpm-build 0fba15
  g_main_context_push_thread_default (context);
rpm-build 0fba15
rpm-build 0fba15
  /* Put together various ref configuration files. */
rpm-build 0fba15
  g_autofree gchar *collection0_uri = assert_create_remote (fixture, "org.example.Collection0",
rpm-build 0fba15
                                                            "exampleos/x86_64/ref0",
rpm-build 0fba15
                                                            "exampleos/x86_64/ref1",
rpm-build 0fba15
                                                            NULL);
rpm-build 0fba15
  g_autofree gchar *collection1_uri = assert_create_remote (fixture, "org.example.Collection1",
rpm-build 0fba15
                                                            "exampleos/x86_64/ref2",
rpm-build 0fba15
                                                            NULL);
rpm-build 0fba15
  g_autofree gchar *no_collection_uri = assert_create_remote (fixture, NULL,
rpm-build 0fba15
                                                              "exampleos/x86_64/ref3",
rpm-build 0fba15
                                                              NULL);
rpm-build 0fba15
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote0", collection0_uri, "org.example.Collection0");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote1", collection1_uri, "org.example.Collection1");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote0-copy", collection0_uri, "org.example.Collection0");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote1-bad-copy", collection1_uri, "org.example.NotCollection1");
rpm-build 0fba15
  assert_create_remote_config (fixture->parent_repo, "remote2", no_collection_uri, NULL);
rpm-build 0fba15
rpm-build 0fba15
  finders[0] = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ());
rpm-build 0fba15
rpm-build 0fba15
  /* Resolve the refs. */
rpm-build 0fba15
  ostree_repo_find_remotes_async (fixture->parent_repo, refs,
rpm-build 0fba15
                                  NULL, finders,
rpm-build 0fba15
                                  NULL, NULL, result_cb, &result);
rpm-build 0fba15
rpm-build 0fba15
  while (result == NULL)
rpm-build 0fba15
    g_main_context_iteration (context, TRUE);
rpm-build 0fba15
rpm-build 0fba15
  results = ostree_repo_find_remotes_finish (fixture->parent_repo,
rpm-build 0fba15
                                             result, &error);
rpm-build 0fba15
  g_assert_no_error (error);
rpm-build 0fba15
  g_assert_nonnull (results);
rpm-build 0fba15
  g_assert_cmpuint (g_strv_length ((char **) results), ==, 3);
rpm-build 0fba15
rpm-build 0fba15
  /* Check that the results are correct: the invalid refs should have been
rpm-build 0fba15
   * ignored, and the valid results canonicalised and deduplicated. */
rpm-build 0fba15
  for (i = 0; results[i] != NULL; i++)
rpm-build 0fba15
    {
rpm-build 0fba15
      const char *ref0_checksum, *ref1_checksum, *ref2_checksum, *ref3_checksum;
rpm-build 0fba15
      guint64 *ref0_timestamp, *ref1_timestamp, *ref2_timestamp, *ref3_timestamp;
rpm-build 0fba15
rpm-build 0fba15
      if (g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote0") == 0 ||
rpm-build 0fba15
          g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote0-copy") == 0)
rpm-build 0fba15
        {
rpm-build 0fba15
          g_assert_cmpuint (g_hash_table_size (results[i]->ref_to_checksum), ==, 5);
rpm-build 0fba15
rpm-build 0fba15
          ref0_checksum = g_hash_table_lookup (results[i]->ref_to_checksum, &ref0);
rpm-build 0fba15
          g_assert_true (ostree_validate_checksum_string (ref0_checksum, NULL));
rpm-build 0fba15
rpm-build 0fba15
          ref1_checksum = g_hash_table_lookup (results[i]->ref_to_checksum, &ref1);
rpm-build 0fba15
          g_assert_true (ostree_validate_checksum_string (ref1_checksum, NULL));
rpm-build 0fba15
rpm-build 0fba15
          ref2_checksum = g_hash_table_lookup (results[i]->ref_to_checksum, &ref2);
rpm-build 0fba15
          g_assert (ref2_checksum == NULL);
rpm-build 0fba15
rpm-build 0fba15
          g_assert_cmpuint (g_hash_table_size (results[i]->ref_to_timestamp), ==, 5);
rpm-build 0fba15
rpm-build 0fba15
          ref0_timestamp = g_hash_table_lookup (results[i]->ref_to_timestamp, &ref0);
rpm-build 0fba15
          *ref0_timestamp = GUINT64_FROM_BE (*ref0_timestamp);
rpm-build 0fba15
          g_assert_cmpuint (*ref0_timestamp, >, 0);
rpm-build 0fba15
rpm-build 0fba15
          ref1_timestamp = g_hash_table_lookup (results[i]->ref_to_timestamp, &ref1);
rpm-build 0fba15
          *ref1_timestamp = GUINT64_FROM_BE (*ref1_timestamp);
rpm-build 0fba15
          g_assert_cmpuint (*ref1_timestamp, >, 0);
rpm-build 0fba15
rpm-build 0fba15
          ref2_timestamp = g_hash_table_lookup (results[i]->ref_to_timestamp, &ref2);
rpm-build 0fba15
          *ref2_timestamp = GUINT64_FROM_BE (*ref2_timestamp);
rpm-build 0fba15
          g_assert_cmpuint (*ref2_timestamp, ==, 0);
rpm-build 0fba15
rpm-build 0fba15
          g_assert_cmpstr (ostree_remote_get_url (results[i]->remote), ==, collection0_uri);
rpm-build 0fba15
        }
rpm-build 0fba15
      else if (g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote1") == 0)
rpm-build 0fba15
        {
rpm-build 0fba15
          g_assert_cmpuint (g_hash_table_size (results[i]->ref_to_checksum), ==, 5);
rpm-build 0fba15
rpm-build 0fba15
          ref3_checksum = g_hash_table_lookup (results[i]->ref_to_checksum, &ref3);
rpm-build 0fba15
          g_assert_true (ostree_validate_checksum_string (ref3_checksum, NULL));
rpm-build 0fba15
rpm-build 0fba15
          ref0_checksum = g_hash_table_lookup (results[i]->ref_to_checksum, &ref0);
rpm-build 0fba15
          g_assert (ref0_checksum == NULL);
rpm-build 0fba15
rpm-build 0fba15
          g_assert_cmpuint (g_hash_table_size (results[i]->ref_to_timestamp), ==, 5);
rpm-build 0fba15
rpm-build 0fba15
          ref3_timestamp = g_hash_table_lookup (results[i]->ref_to_timestamp, &ref3);
rpm-build 0fba15
          *ref3_timestamp = GUINT64_FROM_BE (*ref3_timestamp);
rpm-build 0fba15
          g_assert_cmpuint (*ref3_timestamp, >, 0);
rpm-build 0fba15
rpm-build 0fba15
          ref0_timestamp = g_hash_table_lookup (results[i]->ref_to_timestamp, &ref0);
rpm-build 0fba15
          *ref0_timestamp = GUINT64_FROM_BE (*ref0_timestamp);
rpm-build 0fba15
          g_assert_cmpuint (*ref0_timestamp, ==, 0);
rpm-build 0fba15
rpm-build 0fba15
          g_assert_cmpstr (ostree_remote_get_url (results[i]->remote), ==, collection1_uri);
rpm-build 0fba15
        }
rpm-build 0fba15
      else
rpm-build 0fba15
        {
rpm-build 0fba15
          g_assert_not_reached ();
rpm-build 0fba15
        }
rpm-build 0fba15
    }
rpm-build 0fba15
rpm-build 0fba15
  g_main_context_pop_thread_default (context);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
int main (int argc, char **argv)
rpm-build 0fba15
{
rpm-build 0fba15
  setlocale (LC_ALL, "");
rpm-build 0fba15
  g_test_init (&argc, &argv, NULL);
rpm-build 0fba15
rpm-build 0fba15
  g_test_add_func ("/repo-finder-config/init", test_repo_finder_config_init);
rpm-build 0fba15
  g_test_add ("/repo-finder-config/no-configs", Fixture, NULL, setup,
rpm-build 0fba15
              test_repo_finder_config_no_configs, teardown);
rpm-build 0fba15
  g_test_add ("/repo-finder-config/mixed-configs", Fixture, NULL, setup,
rpm-build 0fba15
              test_repo_finder_config_mixed_configs, teardown);
rpm-build 0fba15
  g_test_add ("/repo-finder-config/find-remotes", Fixture, NULL, setup,
rpm-build 0fba15
              test_repo_finder_config_find_remotes, teardown);
rpm-build 0fba15
rpm-build 0fba15
  return g_test_run();
rpm-build 0fba15
}