1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 /**
28 * Unit tests for FASTQ loader
29 */
30 #include <ktst/unit_test.hpp>
31
32 #include <kfs/directory.h>
33
34 #include <kfg/kfg-priv.h>
35
36 #include "../../tools/vdb-config/vdb-config-model.cpp"
37 #include "../../tools/vdb-config/util.cpp"
38
39 TEST_SUITE(VdbConfStridesModelTestSuite);
40
41 class VdbModelFixture
42 {
43 public:
VdbModelFixture()44 VdbModelFixture()
45 {
46 }
~VdbModelFixture()47 ~VdbModelFixture()
48 {
49 }
50
51 CKConfig kfg;
52 };
53
FIXTURE_TEST_CASE(get_config_changed,VdbModelFixture)54 FIXTURE_TEST_CASE( get_config_changed, VdbModelFixture )
55 {
56 vdbconf_model m ( kfg );
57 REQUIRE ( ! m . get_config_changed () );
58 }
59
FIXTURE_TEST_CASE(prefetch_download_to_cache,VdbModelFixture)60 FIXTURE_TEST_CASE( prefetch_download_to_cache, VdbModelFixture )
61 {
62 vdbconf_model m ( kfg );
63 REQUIRE ( m . does_prefetch_download_to_cache() ); // true by default
64 m . set_prefetch_download_to_cache( false );
65 REQUIRE ( ! m . does_prefetch_download_to_cache() );
66 REQUIRE ( m . get_config_changed () );
67 }
68
FIXTURE_TEST_CASE(user_accept_aws_charges,VdbModelFixture)69 FIXTURE_TEST_CASE( user_accept_aws_charges, VdbModelFixture )
70 {
71 vdbconf_model m ( kfg );
72 REQUIRE ( ! m . does_user_accept_aws_charges() ); // false by default
73 m . set_user_accept_aws_charges( true );
74 REQUIRE ( m . does_user_accept_aws_charges() );
75 REQUIRE ( m . get_config_changed () );
76 }
77
FIXTURE_TEST_CASE(user_accept_gcp_charges,VdbModelFixture)78 FIXTURE_TEST_CASE( user_accept_gcp_charges, VdbModelFixture )
79 {
80 vdbconf_model m ( kfg );
81 REQUIRE ( ! m . does_user_accept_gcp_charges() ); // false by default
82 m . set_user_accept_gcp_charges( true );
83 REQUIRE ( m . does_user_accept_gcp_charges() );
84 REQUIRE ( m . get_config_changed () );
85 }
86
FIXTURE_TEST_CASE(temp_cache_location,VdbModelFixture)87 FIXTURE_TEST_CASE( temp_cache_location, VdbModelFixture )
88 {
89 vdbconf_model m ( kfg );
90 REQUIRE_EQ ( string(), m . get_temp_cache_location() );
91 m . set_temp_cache_location( "path" );
92 REQUIRE_EQ ( string ( "path" ), m . get_temp_cache_location() );
93 REQUIRE ( m . get_config_changed () );
94 }
95
FIXTURE_TEST_CASE(gcp_credential_file_location,VdbModelFixture)96 FIXTURE_TEST_CASE( gcp_credential_file_location, VdbModelFixture )
97 {
98 vdbconf_model m ( kfg );
99 REQUIRE_EQ ( string(), m . get_gcp_credential_file_location() );
100 m . set_gcp_credential_file_location( "path" );
101 REQUIRE_EQ ( string ( "path" ), m . get_gcp_credential_file_location() );
102 REQUIRE ( m . get_config_changed () );
103 }
104
FIXTURE_TEST_CASE(aws_credential_file_location,VdbModelFixture)105 FIXTURE_TEST_CASE( aws_credential_file_location, VdbModelFixture )
106 {
107 vdbconf_model m ( kfg );
108 REQUIRE_EQ ( string(), m . get_aws_credential_file_location() );
109 m . set_aws_credential_file_location( "path" );
110 REQUIRE_EQ ( string ( "path" ), m . get_aws_credential_file_location() );
111 REQUIRE ( m . get_config_changed () );
112 }
113
FIXTURE_TEST_CASE(aws_profile,VdbModelFixture)114 FIXTURE_TEST_CASE( aws_profile, VdbModelFixture )
115 {
116 vdbconf_model m ( kfg );
117 REQUIRE_EQ ( string( "default" ), m . get_aws_profile() );
118 m . set_aws_profile( "path" );
119 REQUIRE_EQ ( string ( "path" ), m . get_aws_profile() );
120 REQUIRE ( m . get_config_changed () );
121 }
122
FIXTURE_TEST_CASE(noCommit,VdbModelFixture)123 FIXTURE_TEST_CASE( noCommit, VdbModelFixture )
124 {
125 bool saved = vdbconf_model( kfg ) . is_http_proxy_enabled ();
126
127 {
128 CKConfig konfig;
129 vdbconf_model model ( konfig );
130 model . set_http_proxy_enabled ( ! saved );
131 // no commit
132 }
133
134 { // did not change on disk
135 CKConfig konfig;
136 vdbconf_model model ( konfig );
137 REQUIRE_EQ ( saved, model . is_http_proxy_enabled() );
138 }
139 }
140
FIXTURE_TEST_CASE(Commit,VdbModelFixture)141 FIXTURE_TEST_CASE( Commit, VdbModelFixture )
142 {
143 vdbconf_model m ( kfg );
144 bool saved = m . has_http_proxy_env_higher_priority ();
145
146 {
147 CKConfig konfig;
148 vdbconf_model model ( konfig );
149 model . set_http_proxy_env_higher_priority ( ! saved );
150 REQUIRE ( model . commit () );
151 REQUIRE ( ! model . get_config_changed () );
152 }
153
154 { // did change on disk
155 CKConfig konfig;
156 vdbconf_model model ( konfig );
157 REQUIRE_EQ ( ! saved, model . has_http_proxy_env_higher_priority() );
158 }
159
160 // clean up
161 m . set_http_proxy_env_higher_priority ( saved );
162 REQUIRE ( m . commit () );
163 }
164
FIXTURE_TEST_CASE(Reload,VdbModelFixture)165 FIXTURE_TEST_CASE( Reload, VdbModelFixture )
166 {
167 vdbconf_model m ( kfg );
168 bool saved = m . has_http_proxy_env_higher_priority ();
169 m . set_http_proxy_env_higher_priority ( ! saved );
170 REQUIRE_EQ ( ! saved, m . has_http_proxy_env_higher_priority() );
171 REQUIRE ( m . get_config_changed () );
172
173 m.reload();
174
175 REQUIRE ( ! m . get_config_changed () );
176 REQUIRE_EQ ( saved, m . has_http_proxy_env_higher_priority() );
177 }
178
179 //////////////////////////////////////////// Main
180 extern "C"
181 {
182
183 #include <kapp/args.h>
184 #include <kfg/config.h>
185
KAppVersion(void)186 ver_t CC KAppVersion ( void )
187 {
188 return 0x1000000;
189 }
UsageSummary(const char * progname)190 rc_t CC UsageSummary (const char * progname)
191 {
192 return 0;
193 }
194
Usage(const Args * args)195 rc_t CC Usage ( const Args * args )
196 {
197 return 0;
198 }
199
200 const char UsageDefaultName[] = "wb-test-fastq";
201
KMain(int argc,char * argv[])202 rc_t CC KMain ( int argc, char *argv [] )
203 {
204 // do not disable user settings as we need to update them as part of the testing
205 //KConfigDisableUserSettings();
206
207 rc_t rc=VdbConfStridesModelTestSuite(argc, argv);
208 return rc;
209 }
210
211 }
212