Skip to content

Commit 5621a2f

Browse files
committed
Add unit tests for variant/->map & variant/exclude?
1 parent 54456e2 commit 5621a2f

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

test/docker_clojure/variant_test.clj

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
(ns docker-clojure.variant-test
2-
(:require [clojure.test :refer :all]
3-
[docker-clojure.variant :refer :all]
4-
[docker-clojure.config :as cfg]))
2+
(:refer-clojure :exclude [compare sort])
3+
(:require [clojure.string :as str]
4+
[clojure.test :refer :all]
5+
[docker-clojure.config :as cfg]
6+
[docker-clojure.core :as-alias core]
7+
[docker-clojure.variant :refer :all]))
58

69
(deftest ->map-test
710
(testing "returns the expected map version of the image variant list"
@@ -17,4 +20,46 @@
1720
:maintainer "Paul Lam <[email protected]> & Wes Morgan <[email protected]>"
1821
:architecture "i386"}
1922
(->map '("eclipse-temurin" 8 :distro/distro
20-
["build-tool" "1.2.3"] "i386")))))))
23+
["build-tool" "1.2.3"] "i386"))))
24+
25+
(is (= {:jdk-version 22
26+
:base-image "debian"
27+
:base-image-tag "debian:bookworm"
28+
:distro :debian/bookworm
29+
:build-tool "tools-deps"
30+
:docker-tag "temurin-22-tools-deps-1.12.0.1530"
31+
:build-tool-version "1.12.0.1530"
32+
:maintainer "Paul Lam <[email protected]> & Wes Morgan <[email protected]>"
33+
:architecture "arm64"}
34+
(->map '("debian" 22 :debian/bookworm
35+
["tools-deps" "1.12.0.1530"] "arm64"))))
36+
37+
(is (= {:jdk-version 22
38+
:base-image "debian"
39+
:base-image-tag "debian:bookworm"
40+
:distro :debian/bookworm
41+
:build-tool ::core/all
42+
:docker-tag "latest"
43+
:build-tool-version nil
44+
:build-tool-versions cfg/build-tools
45+
:maintainer "Paul Lam <[email protected]> & Wes Morgan <[email protected]>"
46+
:architecture "arm64"}
47+
(->map '("debian" 22 :debian/bookworm
48+
[::core/all] "arm64")))))))
49+
50+
(deftest exclude?-test
51+
(testing "gets excluded if contains every key-value pair in exclusion"
52+
(is (exclude? {:foo "bar" :baz "qux" :other "thingy"}
53+
{:foo "bar" :baz "qux"})))
54+
(testing "gets excluded if pred fn returns true"
55+
(is (exclude? {:foo "bar" :baz "qux" :other "thingy"}
56+
{:foo #(str/starts-with? % "b") :baz "qux"})))
57+
(testing "remains included if missing one key-value pair from exclusion"
58+
(is (not (exclude? {:foo "bar" :other "thingy"}
59+
{:foo "bar" :baz "qux"}))))
60+
(testing "remains included if key's value doesn't match exclusion's"
61+
(is (not (exclude? {:foo "burp" :baz "qux" :other "thingy"}
62+
{:foo "bar" :baz "qux"}))))
63+
(testing "remains included if pred fn returns false"
64+
(is (not (exclude? {:foo "bar" :baz "qux" :other "thingy"}
65+
{:foo "bar" :baz #(> (count %) 3)})))))

0 commit comments

Comments
 (0)