<commit_before>(ns puppetlabs.services.master.master-core-test
  (:require [clojure.test :refer :all]
            [puppetlabs.services.master.master-core :refer :all]
            [ring.mock.request :as mock]
            [schema.test :as schema-test]
            [puppetlabs.comidi :as comidi]
            [puppetlabs.services.protocols.jruby-puppet :as jruby]
            [puppetlabs.trapperkeeper.testutils.logging :as logging]
            [ring.util.response :as rr]
            [ring.mock.request :as ring-mock]
            [puppetlabs.kitchensink.core :as ks]
            [ring.middleware.params :as ring])
  (:import (java.util HashMap)))

(use-fixtures :once schema-test/validate-schemas)

(def dummy-jruby-service
  (reify jruby/JRubyPuppetService))

(defn build-ring-handler
  [request-handler puppet-version jruby-service]
  (-> (root-routes request-handler #(ring/wrap-params %) jruby-service (constantly nil))
      (comidi/routes->handler)
      (wrap-middleware puppet-version)))

(defn app-request
  ([app path] (app-request app :get path))
  ([app method path] (app (mock/request method path))))

(deftest test-master-routes
  (let [handler     (fn ([req] {:request req}))
        app         (build-ring-handler handler "1.2.3" dummy-jruby-service)
        request     (partial app-request app)]
    (is (= 200 (:status (request "/v3/environments"))))
    (is (= 200 (:status (request "/v3/catalog/bar?environment=environment1234"))))
    (is (= 200 (:status (app (-> {:request-method :post
                                  :uri "/v3/catalog/bar"
                                  :content-type "application/x-www-form-urlencoded"}
                                 (mock/body "environment=environment1234"))))))<commit_msg>(SERVER-1142) Remove anonymous function in master-core-test ring-handler<commit_after>(ns puppetlabs.services.master.master-core-test
  (:require [clojure.test :refer :all]
            [puppetlabs.services.master.master-core :refer :all]
            [ring.mock.request :as mock]
            [schema.test :as schema-test]
            [puppetlabs.comidi :as comidi]
            [puppetlabs.services.protocols.jruby-puppet :as jruby]
            [puppetlabs.trapperkeeper.testutils.logging :as logging]
            [ring.util.response :as rr]
            [ring.mock.request :as ring-mock]
            [puppetlabs.kitchensink.core :as ks]
            [ring.middleware.params :as ring])
  (:import (java.util HashMap)))

(use-fixtures :once schema-test/validate-schemas)

(def dummy-jruby-service
  (reify jruby/JRubyPuppetService))

(defn build-ring-handler
  [request-handler puppet-version jruby-service]
  (-> (root-routes request-handler ring/wrap-params jruby-service (constantly nil))
      (comidi/routes->handler)
      (wrap-middleware puppet-version)))

(defn app-request
  ([app path] (app-request app :get path))
  ([app method path] (app (mock/request method path))))

(deftest test-master-routes
  (let [handler     (fn ([req] {:request req}))
        app         (build-ring-handler handler "1.2.3" dummy-jruby-service)
        request     (partial app-request app)]
    (is (= 200 (:status (request "/v3/environments"))))
    (is (= 200 (:status (request "/v3/catalog/bar?environment=environment1234"))))
    (is (= 200 (:status (app (-> {:request-method :post
                                  :uri "/v3/catalog/bar"
                                  :content-type "application/x-www-form-urlencoded"}
                                 (mock/body "environment=environment1234"))))))
{'fraction_non_alphanumeric': 0.14035087719298245, 'fraction_numerical': 0.014148273910582909, 'mean_word_length': 2.5069444444444446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139675', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1097, 'n_words': 233}