Skip to content

Commit

Permalink
TMP: Disable old code
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Aug 30, 2024
1 parent 38c1bbb commit c785b59
Show file tree
Hide file tree
Showing 34 changed files with 143 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions test/k16/kmono/git/files_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
(ns k16.kmono.git.files-test
(:require
[babashka.fs :as fs]
[clojure.test :refer [deftest is use-fixtures]]
[k16.kmono.git.commit :as git.commit]
[k16.kmono.git.files :as git.files]
[k16.kmono.test.helpers.commit :refer [commit]]
[k16.kmono.test.helpers.repo :refer [*repo* with-test-repo] :as helpers.repo]))

(use-fixtures :each with-test-repo)

(defn prepare-repo []
(let [root-commit (git.commit/get-current-commit *repo*)

_ (fs/create-file (fs/file *repo* "packages/a/change-1"))
_ (fs/create-file (fs/file *repo* "packages/b/change-1"))

commit-1 (commit *repo* "change-1")

_ (fs/create-file (fs/file *repo* "packages/a/change-2"))
_ (fs/create-file (fs/file *repo* "packages/b/change-2"))

_ (commit *repo* "change-2")]

[root-commit commit-1]))

(deftest query-ordered-tags
(let [[root-commit commit-1] (prepare-repo)

files-since-root
(git.files/find-changed-files-since
*repo* {:ref root-commit})

files-since-change-1
(git.files/find-changed-files-since
*repo* {:ref commit-1})]

(is (= ["packages/a/change-1"
"packages/a/change-2"
"packages/b/change-1"
"packages/b/change-2"]
files-since-root))

(is (= ["packages/a/change-2"
"packages/b/change-2"]
files-since-change-1))))

(deftest query-ordered-tags-in-subdir
(let [[root-commit commit-1] (prepare-repo)

files-since-root-a
(git.files/find-changed-files-since
*repo* {:ref root-commit
:subdir "packages/a"})

files-since-change-1-b
(git.files/find-changed-files-since
*repo* {:ref commit-1
:subdir "packages/b"})]

(is (= ["packages/a/change-1"
"packages/a/change-2"]
files-since-root-a))

(is (= ["packages/b/change-2"]
files-since-change-1-b))))
32 changes: 32 additions & 0 deletions test/k16/kmono/git/tag_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(ns k16.kmono.git.tag-test
(:require
[clojure.test :refer [deftest is use-fixtures]]
[k16.kmono.git.command :as git]
[k16.kmono.git.commit :as git.commit]
[k16.kmono.git.tags :as git.tags]
[k16.kmono.test.helpers.commit :refer [commit]]
[k16.kmono.test.helpers.repo :refer [*repo* with-test-repo] :as helpers.repo]))

(use-fixtures :each with-test-repo)

(deftest query-ordered-tags
(let [initial-commit (git.commit/get-current-commit *repo*)]

(git.tags/create-tags *repo* {:ref initial-commit
:tags ["a"]})

(commit *repo* "change-1")

(git.tags/create-tags *repo* {:ref (git.commit/get-current-commit *repo*)
:tags ["b-1"]})

(git/run-cmd! *repo* "git" "checkout" initial-commit)

(commit *repo* "change-2")

(git.tags/create-tags *repo* {:ref (git.commit/get-current-commit *repo*)
:tags ["b-2"]})

(let [tags (git.tags/get-sorted-tags *repo* (git.commit/get-current-commit *repo*))]

(is (= ["b-2" "a"] tags)))))
11 changes: 11 additions & 0 deletions test/k16/kmono/test/helpers/commit.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns k16.kmono.test.helpers.commit
(:require
[k16.kmono.git.commit :as git.commit]
[k16.kmono.git.command :as git]))

(defn commit
([repo] (commit repo "commit"))
([repo message]
(git/run-cmd! repo "git add .")
(git/run-cmd! repo "git commit --allow-empty" "-m" message)
(git.commit/get-current-commit repo)))
30 changes: 30 additions & 0 deletions test/k16/kmono/test/helpers/repo.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns k16.kmono.test.helpers.repo
(:require
[babashka.fs :as fs]
[k16.kmono.git.command :as git]))

(defn setup-multi-package-repo []
(let [uuid (str (random-uuid))

repo (fs/file (str "test/.repos/" uuid))]
(fs/create-dirs repo)
(fs/copy-tree (fs/file "test/templates/monorepo")
repo)

(git/run-cmd! repo "git" "init")
(git/run-cmd! repo "git" "add" ".")
(git/run-cmd! repo "git" "commit" "-m" "init")

(git/run-cmd! repo "git config advice.detachedHead false")

(.getAbsolutePath repo)))

(def ^:dynamic *repo* nil)

(defn with-test-repo [test]
(let [repo (setup-multi-package-repo)]
(try
(binding [*repo* repo]
(test))
(finally
(fs/delete-tree repo)))))
1 change: 1 addition & 0 deletions test/templates/monorepo/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:kmono/workspace {}}
1 change: 1 addition & 0 deletions test/templates/monorepo/packages/a/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:kmono/package {}}
1 change: 1 addition & 0 deletions test/templates/monorepo/packages/b/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:kmono/package {}}
1 change: 1 addition & 0 deletions test/templates/monorepo/packages/excluded/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit c785b59

Please sign in to comment.