{"id":32178655,"url":"https://github.com/stalefruits/fixpoint","last_synced_at":"2025-12-12T01:24:12.445Z","repository":{"id":62434782,"uuid":"85070357","full_name":"stalefruits/fixpoint","owner":"stalefruits","description":"Clojure Test Fixtures \u0026 Datasources","archived":false,"fork":false,"pushed_at":"2017-08-11T12:22:37.000Z","size":99,"stargazers_count":30,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-21T20:58:48.038Z","etag":null,"topics":["fixtures","testing"],"latest_commit_sha":null,"homepage":"http://blog.stylefruits.tech/fixpoint/","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stalefruits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-15T12:35:17.000Z","updated_at":"2025-06-04T20:51:34.000Z","dependencies_parsed_at":"2022-11-01T21:02:37.325Z","dependency_job_id":null,"html_url":"https://github.com/stalefruits/fixpoint","commit_stats":null,"previous_names":["stylefruits/fixpoint"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/stalefruits/fixpoint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalefruits%2Ffixpoint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalefruits%2Ffixpoint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalefruits%2Ffixpoint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalefruits%2Ffixpoint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stalefruits","download_url":"https://codeload.github.com/stalefruits/fixpoint/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalefruits%2Ffixpoint/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280333502,"owners_count":26312845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fixtures","testing"],"created_at":"2025-10-21T20:58:51.213Z","updated_at":"2025-10-21T20:58:52.410Z","avatar_url":"https://github.com/stalefruits.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fixpoint\n\n__fixpoint__ is a library offering a simple and powerful way of setting up\ntest datastores and data.\n\n[![Build Status](https://travis-ci.org/stylefruits/fixpoint.svg?branch=master)](https://travis-ci.org/stylefruits/fixpoint)\n[![Clojars Artifact](https://img.shields.io/clojars/v/stylefruits/fixpoint.svg)](https://clojars.org/stylefruits/fixpoint)\n\nReady-to-use components for [PostgreSQL][postgres], [MySQL][mysql] and\n[ElasticSearch][elastic], as well as an [AMQP Broker][qpid] are already included.\n\n[postgres]: https://www.postgresql.org/\n[mysql]: https://www.mysql.com/\n[elastic]: https://www.elastic.co/products/elasticsearch\n[qpid]: https://qpid.apache.org/\n\n## Usage\n\n```clojure\n(require '[fixpoint.core :as fix]\n         '[fixpoint.datasource.postgresql :as pg])\n```\n\nSet up a datasource and give it an ID to be used later, e.g. to set up a\nPostgreSQL database and call it `:test-db`:\n\n\n```clojure\n(def test-db\n  (pg/make-datasource\n    :test-db\n    {:connection-uri \"jdbc:postgresql://...\"}))\n```\n\nSet up test fixture functions. Use `fix/as` to specify a name for a specific\nfixture document that can be used in other fixture documents to refer to it.\nUse `fix/on-datasource` to specify which datasource the fixture should\nget inserted in, e.g.:\n\n```clojure\n(defn- person\n  [reference name age]\n  (-\u003e {:db/table :people\n       :name     name\n       :age      age\n       :active   true}\n      (fix/as reference)\n      (fix/on-datasource :test-db)))\n\n(defn- post\n  [reference person-reference text]\n  (-\u003e {:db/table  :posts\n       :text      text\n       :author-id person-reference}\n      (fix/as reference)\n      (fix/on-datasource :test-db)))\n```\n\nNote that you can also return a seq (or nested ones) of fixtures, allowing\nyou to cover multiple datapoints within one fixture function. Check out\ninstantiation of those fixtures:\n\n```clojure\n(def +fixtures+\n  [(person :person/me  \"me\" 27)\n   (person :person/you \"you\" 29)\n   (post   :post/happy :person/me  \"Awesome.\")\n   (post   :post/meh   :person/you \"Meh.\")])\n```\n\nNote the cross-references between entities, using namespaced keywords. They,\nby default, resolve to the `:id` field of the respective inserted data. You can\nalso do a lookup within, e.g. to create a post with the same author as another:\n\n```clojure\n(post :post/question [:post/happy :author-id] \"Do you really think so?\")\n```\n\nOf course, so far nothing has happened since we haven't brought our datasource\nand fixtures together. Let's start up the datasource, ensuring rollback after\nwe're done, insert our fixtures and check out the inserted data.\n\n```clojure\n(fix/with-rollback-datasource [_ test-db]\n  (fix/with-data +fixtures+\n    (vector\n      (fix/property :person/me)\n      (fix/property :person/you :created-at)\n      (fix/property :post/happy :author-id)\n      (fix/id :post/meh))))\n;; =\u003e [{:id 3,\n;;      :name \"me\",\n;;      :age 27,\n;;      :active true,\n;;      :created-at #inst \"2017-03-10T11:13:06.452505000-00:00\"},\n;;     #inst \"2017-03-10T11:13:06.452505000-00:00\"\n;;     3\n;;     4]\n```\n\nCool, eh?\n\n## Integration with Clojure Tests\n\nfixpoint functionality can be used as part of `clojure.test` fixtures. Note that\nthe datasource fixture has to be applied before the data fixture:\n\n```clojure\n(require '[clojure.test :refer :all]\n         '[clojure.java.jdbc :as jdbc])\n\n(use-fixtures\n  :once\n  (fix/use-datasources db)\n  (fix/use-data +fixtures+))\n\n(deftest t-people-query\n  (let [db (fix/raw-datasource :test-db)]\n    (is (= #{\"me\" \"you\" \"someone\"}\n           (-\u003e\u003e (jdbc/query db [\"select name from people\"])\n                (map :name)\n                (set))))))\n```\n\nThis, as you might have noticed, should fail:\n\n```clojure\n(run-tests)\n;; FAIL in (t-people-query) (b88f62883cbaa1a3f26472a814829fe3c5933107-init.clj:3)\n;; expected: (= #{\"someone\" \"you\" \"me\"} (-\u003e\u003e (db/query db [\"select name from people\"]) (map :name) (set)))\n;;  actual: (not (= #{\"someone\" \"you\" \"me\"} #{\"you\" \"me\"}))\n;;\n;; Ran 1 tests containing 1 assertions.\n;; 1 failures, 0 errors.\n;; =\u003e {:test 1, :pass 0, :fail 1, :error 0, :type :summary}\n```\n\n## License\n\nCopyright \u0026copy; 2017 stylefruits GmbH\n\nThis project is licensed under the [Apache License 2.0][license].\n\n[license]: http://www.apache.org/licenses/LICENSE-2.0.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstalefruits%2Ffixpoint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstalefruits%2Ffixpoint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstalefruits%2Ffixpoint/lists"}