[Groonga-commit] groonga/groonga [command-version] allow command_version option.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 9月 15日 (水) 11:15:03 JST


Kouhei Sutou	2010-09-15 02:15:03 +0000 (Wed, 15 Sep 2010)

  New Revision: da0464af5425657c8c0d8d52285e8c0e098564e4

  Log:
    allow command_version option.

  Modified files:
    lib/ctx.c
    test/unit/gqtp/test-status.rb
    test/unit/http/test-http.rb

  Modified: lib/ctx.c (+24 -0)
===================================================================
--- lib/ctx.c    2010-09-15 02:13:05 +0000 (1a29e57)
+++ lib/ctx.c    2010-09-15 02:15:03 +0000 (bc9e5cb)
@@ -895,10 +895,24 @@ grn_str_get_mime_type(grn_ctx *ctx, const char *p, const char *pe,
   }
 }
 
+static void
+get_command_version(grn_ctx *ctx, const char *p, const char *pe)
+{
+  grn_command_version version;
+  const char *rest;
+
+  version = grn_atoui(p, pe, &rest);
+  if (pe == rest) {
+    grn_ctx_set_command_version(ctx, version);
+  }
+}
+
 #define INDEX_HTML "index.html"
 #define OUTPUT_TYPE "output_type"
+#define COMMAND_VERSION "command_version"
 #define EXPR_MISSING "expr_missing"
 #define OUTPUT_TYPE_LEN (sizeof(OUTPUT_TYPE) - 1)
+#define COMMAND_VERSION_LEN (sizeof(COMMAND_VERSION) - 1)
 
 static inline int
 command_proc_p(grn_obj *expr)
@@ -931,6 +945,11 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len)
         p = grn_text_cgidec(ctx, &buf, p, e, '&');
         v = GRN_TEXT_VALUE(&buf);
         get_content_mime_type(ctx, v, GRN_BULK_CURR(&buf));
+      } else if (l == COMMAND_VERSION_LEN &&
+                 !memcmp(v, COMMAND_VERSION, COMMAND_VERSION_LEN)) {
+        GRN_BULK_REWIND(&buf);
+        p = grn_text_cgidec(ctx, &buf, p, e, '&');
+        get_command_version(ctx, GRN_TEXT_VALUE(&buf), GRN_BULK_CURR(&buf));
       } else {
         if (!(val = grn_expr_get_or_add_var(ctx, expr, v, l))) {
           val = &buf;
@@ -981,6 +1000,11 @@ grn_ctx_qe_exec(grn_ctx *ctx, const char *str, uint32_t str_len)
           p = grn_text_unesc_tok(ctx, &buf, p, e, &tok_type);
           v = GRN_TEXT_VALUE(&buf);
           get_content_mime_type(ctx, v, GRN_BULK_CURR(&buf));
+        } else if (l == COMMAND_VERSION_LEN &&
+                   !memcmp(v, COMMAND_VERSION, COMMAND_VERSION_LEN)) {
+          GRN_BULK_REWIND(&buf);
+          p = grn_text_unesc_tok(ctx, &buf, p, e, &tok_type);
+          get_command_version(ctx, GRN_TEXT_VALUE(&buf), GRN_BULK_CURR(&buf));
         } else if (expr && (val = grn_expr_get_or_add_var(ctx, expr, v, l))) {
           grn_obj_reinit(ctx, val, GRN_DB_TEXT, 0);
           p = grn_text_unesc_tok(ctx, val, p, e, &tok_type);

  Modified: test/unit/gqtp/test-status.rb (+6 -1)
===================================================================
--- test/unit/gqtp/test-status.rb    2010-09-15 02:13:05 +0000 (9c5e674)
+++ test/unit/gqtp/test-status.rb    2010-09-15 02:15:03 +0000 (97a8a92)
@@ -26,8 +26,13 @@ class StatusTest < Test::Unit::TestCase
     teardown_local_database
   end
 
-  def test_status_exit_successfully
+  def test_exit_successfully
     output = run_groonga(@database_path, "status")
     assert_predicate($?, :success?)
   end
+
+  def test_command_version
+    output = run_groonga(@database_path, "status", "--command_version", "1")
+    assert_equal(1, JSON.parse(output)[1]["command_version"])
+  end
 end

  Modified: test/unit/http/test-http.rb (+6 -0)
===================================================================
--- test/unit/http/test-http.rb    2010-09-15 02:13:05 +0000 (2bd67aa)
+++ test/unit/http/test-http.rb    2010-09-15 02:15:03 +0000 (d9fb523)
@@ -37,6 +37,12 @@ class HTTPTest < Test::Unit::TestCase
                  JSON.parse(response.body)[1].keys.sort)
   end
 
+  def test_status_command_version
+    response = get(command_path(:status, :command_version => 1))
+    assert_equal("application/json", response.content_type)
+    assert_equal(1, JSON.parse(response.body)[1]["command_version"])
+  end
+
   def test_quit
     response = get(command_path(:quit))
     assert_success_response(response,




Groonga-commit メーリングリストの案内
Back to archive index