Soon, a minversion header field will be included in the MoM. This change
updates the test library to add a minversion header field to MoMs and adds
functions to create a minversion update. Also, the skip-verified-fullfiles
test was replaced by the update-minversion test. The update-minversion test
verifies that unchanged files with a version bump caused by a minversion
update are skipped during an update.
Signed-off-by: John Akre <john.w.akre@intel.com>
The test library contains a few assertions meant to verify the
existence or non existence of files and directories. In the case
of swupd, it is sometimes common that these files can be in directories
that are not readable by non root users, which is the case of the state
directory.
This commit makes a change so these assertions use root for testing
the existence of these files and directories so we don't get false
positives in the tests.
The commit also adds one more env variable with the --keepcache
option so we can use it in tests that require the state directory
to be persisted.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When a user wants to print to the terminal from a test that
is using the bats framework, it is necessary to use file descriptor
3.
This commit provides a wrapper function called print so it is
easier for user to print to terminal from tests.
Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
When updating the manifest version we were replacing any line with the word
version to "version: new_version". This is a problem now that we are adding
a minversion field to the manifest. That could be a problem too when there
was a file named version.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit adds the iterative manifests (to-manifest) and the delta
manifest (from-manifest) when creating a bundle update. This manifests
should contain only those files that changed in the latest version.
Closes issue #557
There are some cases in the library where sed or awk is used to find
certain lines within files. To match these lines we use a pattern.
In some cases this pattern should be anchored to the beginning of the
line, in case a string with that pattern appears in a file (for example
in a bundle manifest name) in the last field. This is unlikely, but
it's better to avoid unintentional matches.
When a user creates a new version in a test environment and uses
the -r option an updated version of the os-release and format files
are added to the files directory. This is useful for some tests
like update tests.
This commit adds a second step of adding the updated files to the
os-core bundle so it is easier to create updates. With this commit
if using the option -r it means the new version will include an
update to the os-core bundle.
To support clients that need to authenticate with a web server
containing protected swupd content, an SSL certificate should be
presented if defined. This commit enables client certificate
authentication with swupd and adds relevant tests.
credit: gtkramer implemented client certificates in swupd
Signed-off-by: John Akre <john.w.akre@intel.com>
This commit adds the following test objects to testlib:
- start_web_server
- destroy_web_server
This change moves the implementation of web server creation and
destruction from individual tests to the test library.
Signed-off-by: John Akre <john.w.akre@intel.com>
This commit adds functions to testlib for the following:
- generate_certificate
- create_trusted_cacert
- destroy_trusted_cacert
These functions are used to create a self-signed public/private key
pair, create a trusted key store for the test environment with a public
key, and to delete the trusted key store. For the test environment to use
the trusted key store, swupd must be configured using
--with-fallback-capaths=<path to key store>. This configuration option
has been added to autogen and travis.
Signed-off-by: John Akre <john.w.akre@intel.com>
When "uninstalling" a bundle in web-dir it is better not to
remove all files in the bundle's manifest because they may be used
by another bundle, and checking every manifest would be too expensive
for this test task. Removing the bundle manifest and its packs is
enough for testing purposes.
Some functions from the test library can be used by end users to
modify some object from their test environment, for example using
the add_dependency_to_manifest they can add one or many dependencies
to a bundle's manifest. After modifying a bundle's manifest, many
subsequent actions need to occur in order for the objects to still be
valid, the manifest's tar needs to be re-created, since the manifest's
hash changed, the MoM needs to be updated with this new hash, etc.
To minimize the actions an end user needs to do, most of these
activities are automatically performed by most library functions.
However if the function is being called by another function which
expects to perform many actions in the same object, it may not be the
best option to be re-creating those tars and updating the MoM many times
for the same object since it could affect the performance.
This commit adds a -p flag to some functions to tell the functions you only
want a partial update, meaning that you plan on making more changes to the
test object so all those unnecessary changes are not performed.
Normal test environments come with a minimal version of os-core
bundle by default (only one file and the tracking file). Users
also have the option of not having os-core at all with the -e
"empty" option.
This commit adds another option "-r" for creating a test environment
that includes a more complete version of the os-core bundle,
with a couple of useful files: os-release and format. This type
of bundle can be useful when working with some type of tests like
updates.
Some tests need to have not only one but two or more versions of
the server side content (web-dir).
This commit adds a function that can be used to create these new
versions.
It is very common to manipulate manifests when writing tests for
swupd, so in order to make it easier for users, and less error
prone, this commit introduces a function to manipulate data from
a manifest easily.
Having to manually add files to the pack's tar everytime we are
dealing with delta or zero packs is error prone since those packs
should have files in a specific path for them to be used correctly
by swupd client.
This commit introduces a function to add files to zero or delta
packs in a consistent way.
When removing a dummy bundle using the test library, the library
tries to remove bundle files and directories from the file system,
however if the directory that is being removed is not empty, it
will cause the function to exit with a non zero code.
This commit fixes the bug by adding an option for ignoring this
scenario.
When creating a bundle using the testlib functions, if the user
wants the bundle to include files, those files are generated
automatically with random content.
This commit adds the capability of specifying an existing file to
be used for the bundle by using the
"-f <file in manifest>:<file to use>" notation.
When creating a test bundle, if the user didn't select any directory,
file, or link to be added to the bundle, the bundle would add
directory /usr/bin by default so the bundle would not be totally
empty, however since the bundle also always adds the tracking file
(/usr/share/clear/bundles/"$bundle_name") to the bundle, then it is
not necessary, and actually undesired to add /usr/bin by default.
This commit removes the addition of /usr/bin by default.
Test environments have all the basic elements to test swupd-client
and one of those elements is the dummy os-core bundle created and
installed in the target-dir by default. Sometimes, the person
writing a test may need to have a completely empty test environment,
meaning with no os-core bundle.
This commit adds the capability of creating a test environment with
no os-core bundle by default, by using the -e (empty) option. The
commit also modifies the os-core bundle that is being generated by
default from having one file in /ur/bin/core to being just /core,
this way the os-core bundle is smaller and faster to be created,
which is important since it is always added by default to every
test.
When creating bundles, users get to choose if they want to include
files, directories, links or dangling links in the bundle. Whatever
choice they make, all the directories that are part of the path of
the element should be created. This wasn't happening when creating
bundles with nested directories, for example /foo/bar/baz, in this
case only dir /foo/bar/baz was being added to the manifest of the
bundle but neither /foo nor /foo/bar were being added.
This commit fixes that issue. It also adds a safety feature where
it adds a '/' in front of dirs or file when user creates a bundle
in case they forget to add it themselves so the function works
properly even in that situation. For example with something like
this "-f /foo,bar/baz"
There is an issue with the get_hash_from_manifest function where
in some cases if there are two files that share the same path,
both would be picked up.
This commit fixes the issue by being more slective when choosing
the line.
This commit fixes a bug when updating the hashes of manifests in
MoM. When doing this, all bundles were being removed and re-added
to the MoM using the remove_from_manifest and add_to_manifest
functions, but this was having some undesired side effects.
This commit implements the update of hashes in MoM in a different
way.
When removing a file or directory from a manifest the filecount and
contentsize in the manifest were not being decreased. Also after
removing an item from the manifest, the hash of the manifest will
change, which means the person using this function in a test needs
to remember to update the hash of the manifest in the MoM or the
test will fail because the MoM will be discarded as corrupt.
This commit decreases the values of both fields so the manifest is
still accurate after removing elements from it.
Also after removing an element from the manifest, the MoM will have
its hashes automatically updated so to release the end user from
remembering doing this.
Finally this commit include an update for a test that use the
remove_from_manifest function since it doesn't need to update hashes
in the MoM as a separate step any more.
With the current test library a user can create a test bundle and
then add a dependency to that bundle by adding it to the bundle's
manifest. However this only worked if there was only one version
available in the web-server.
A second issue was that after modifying the manifest the hash
in the MoM would need to be updated.
This commit allow users to create a version N, create a bundle
for version N, then create a version N+M and add a dependency to
that bundle in that new version N+M.
It also recalculate all hashes in the MoM so users writing tests
don't need to remember to update them themselves.
Finally this commit includes some updates for some tests that use
the add_dependency_to_manifest function since they don't need to
update hashes in the MoM as a separate step any more.
This commit changes the way the contentsize was being read from the
manifest, making it a little more efficient and easier to read by
replacing a piped call of cat + grep + awk, to only using awk.
It also includes a couple of changes in the comments of the
function so they are more accurate.
The set_env_variables function exports different variables that
are dependent of a specific test environment. This commit adds a
few more variables that can be used to reduce the typing when writing
tests.
Automated tests should create its own test environment including
all needed dependencies when the test starts, and should clean up
after itself once the test is over. Sometimes when developing
these tests, they don't work as expected at first and is difficult
to figure out what the problem is if the test environment is gone.
This commit allow users to temporarily skip the removal of the test
environment so he/she can debug what the problem was by only running
the test with the DEBUG_TEST env variable set to "true".
Example: DEBUG_TEST=true bats my_test.bats
This commit adds the following two assertions:
- assert_files_equal
- assert_files_not_equal
These can be used in tests for validating file equality consistently.
Some variables in the test library were missing the $ character,
whichs makes bash interpret them as strings instead of variables.
This commit fixes the variable names.
The test library should be used to create test cases based on
modular "steps", the test library helps you build these steps,
sometimes is difficult to see what parameters a function from
testlib needs.
This commit adds usage info for every function in the test lib so
it is easier for the person writing test cases to know what parameters
the function needs, by simply executing the function name with no
parameters in the command line will show this info.
Most of the functions of the test library include some type of
parameter validation, when a function is called and one of its
parameters don't comply with the expected parameters it terminates
the whole script. This is expected, but sometimes it can be
difficult to figure out what was the function that received the
incorrect parameters in the script.
This commit adds a function that prints a stack of the function
calls so when a script is terminated it is easier to figure out
the culprit.
The test library includes many assertions intended to validate
a command's output. These assertions take the command output and
compare it against an expected output. Some of these assertions
take a literal string and others take a string with regular
expression values. However, regardless of what king of string is
being used for the expected output, there are some common lines
in the output that are usually not important and are safe to ignore.
An example would be empty lines or lines with only dots.
This commit adds the capability for those assertions to use an
ignore file to include patterns that could be ignored/removed from
the command's output before comparing it against the expected
output. Also with this commit empty lines and lines with only dots
will be ignored by default. If the assertion needs to validate an
exact output without ignoring anything in the ignore-list nor ignoring
dots and blank lines, then the --identical option can be used with
the assertion.
This commit include two parts.
1) It adds 6 new assertions to the test library:
- assert_is_output
- assert_is_not_output
- assert_regex_is_output
- assert_regex_is_not_output
- assert_regex_in_output
- assert_regex_not_in_output
2) It migrates the tests from the following categories to use the
new library:
- completion
- hashdump
- mirror
- search
Finally this commit changes a few test cases so they use
"assert_is_output" instead of "assert_in_output", that way
we can have a tighter control of the output we want since
assert_is_output requires the whole output to match to a
specific text instead of doing a partial match.
This commit adds the following three funtions to the test library:
- install_bundle
- remove_bundle
- clean_state_dir
These functions are useful specially when the global_setup and the
global_teardown are used instead of test_setup and test_teardown.
These functions allow the user to create all of its test resources
in the global_setup and reuse those same resources throughout all
the tests in the test script. By using the global_setup and
global_teardown functions the test execution time can be greatelly
reduced.
This commit also modifies the add-rc.bats and remove-rc.bats to
leverage the global setup and teardowns to increase the execution
speed. These times were reduced as shown:
- bundleadd_v2/add-rc.bats from 1m50.129s -> 0m20.026s
- bundleremove_v2/remove-rc.bats from 0m59.079s -> 0m15.446s
A new test library.bash was introduced that simplifies the creation
of test environments and test objects.
This commit rewrites all existing tests from
test/functional/bundleremove and test/functional/checkupdate but this
time using the new test library.
NOTE: Once all the tests have been rewriten to use the new lib, they
can be included in the Makefile so they are run with every patch,
and the old tests can be deleted.
A new test library.bash was introduced that simplifies the creation
of test environments and test objects.
This commit rewrites all existing tests from test/functional/bundlelist
but this time using the new test library. Once all the tests have been
rewriten to use the new lib, they can be included in the Makefile so
they are run with every patch, and the old tests can be deleted.
This commit adds the last rewritten tests for bundle-add, these
tests are the equivalent to the ones in the bundleadd directory
but using the new test library.
This commit adds some assertions that can be used to validate
common things in a consistent manner among tests.
The assertions added with this commit are the following:
- assert_status_is
- assert_status_is_not
- assert_dir_exists
- assert_dir_not_exists
- assert_file_exists
- assert_file_not_exists
- assert_in_output
- assert_not_in_output
More assertions may be added as needed while migrating the rest of
the tests to use the new testlib.
There is some stuff that is common for every test file, so this
commit adds a function that generates a new test file based on a
template to facilitate test creation.