Browse Source

Ensure that the data in the database matches the current git version

David N. Welton 10 years ago
parent
commit
dd49b0891f
2 changed files with 19 additions and 0 deletions
  1. 2 0
      Makefile
  2. 17 0
      test/epgsql_tests.erl

+ 2 - 0
Makefile

@@ -9,6 +9,8 @@ compile:
 clean:
 	@$(REBAR) clean
 
+# The INSERT is used to make sure the schema_version matches the tests
+# being run.
 create_testdbs:
 	psql template1 < ./test_data/test_schema.sql
 	psql epgsql_test_db1 -c "INSERT INTO schema_version (version) VALUES ('${LASTVERSION}');"

+ 17 - 0
test/epgsql_tests.erl

@@ -755,6 +755,23 @@ run_tests() ->
     eunit:test(Mods, []).
 
 all_test_() ->
+    Version =
+        erlang:list_to_binary(
+          re:replace(os:cmd("git rev-parse HEAD"), "\\s+", "")),
+
+    with_connection(
+      epgsql,
+      fun(C) ->
+              {ok, _Cols, [{DBVersion}]} = epgsql:squery(C, "SELECT version FROM schema_version"),
+              case DBVersion == Version of
+                  false ->
+                      error_logger:info_msg("Git version of test schema does not match: ~p ~p~nPlease run make create_testdbs to update your test databases", [Version, DBVersion]),
+                      erlang:exit(1);
+                  _ ->
+                      undefined
+              end
+      end),
+
     Tests =
         lists:map(
           fun({Name, _}) ->