initial commit

This commit is contained in:
Peter Tillemans 2023-11-26 17:29:15 +01:00
commit a6cf224826
9 changed files with 122 additions and 0 deletions

13
bb.edn Normal file
View file

@ -0,0 +1,13 @@
{:paths ["bb"],
:deps {medley/medley {:mvn/version "1.3.0"}}
:tasks {main testoperenv.main/-main
test:bb {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
:task (exec 'cognitect.test-runner.api/test)
:exec-args {:dirs ["test"]}
:org.babashka/cli {:coerce {:nses [:symbol]
:vars [:symbol]}}}}}

10
bb/testoperenv/#main.clj# Normal file
View file

@ -0,0 +1,10 @@
(ns testoperenv.main
(:require [medley.core :as m]
[babashka.process :as p]
))
(defn -main []
(println "Hello, World!")
(:out (p/shell {:out :string :err :string} "bash" "-c" "echo -n foobar")))

1
bb/testoperenv/.#main.clj Symbolic link
View file

@ -0,0 +1 @@
pti@mars.124815:1695820260

22
bb/testoperenv/cmd.clj Normal file
View file

@ -0,0 +1,22 @@
(ns testoperenv.cmd
(:require [babashka.process :as p]
[clojure.string :as str]
))
(defn cmd-ok? [cmd-result]
(= 0 (:exit cmd-result)))
(defn run-cmd [cmd & args]
(let [cmd-result (apply p/shell {:out :string :err :string} cmd args)]
(if (cmd-ok? cmd-result)
(str/trim (:out cmd-result))
(throw (ex-info "Command failed" cmd-result)))))
(defn run-cmd-in-dir [dir cmd & args]
(let [cmd-result (apply p/shell {:dir dir :out :string :err :string} cmd args)]
(if (cmd-ok? cmd-result)
(str/trim (:out cmd-result))
(throw (ex-info "Command failed" cmd-result)))))

10
bb/testoperenv/main.clj Normal file
View file

@ -0,0 +1,10 @@
(ns testoperenv.main
(:require [medley.core :as m]
[babashka.process :as p]
))
(defn -main []
(println "Hello, World!")
(:out (p/shell {:out :string :err :string} "bash" "-c" "echo -n foobar")))

View file

@ -0,0 +1,7 @@
(ns testoperenv.test-python
(:require [clojure.test :refer [deftest is testing]]))
(deftest test-python
(testing "python is installed"
(is (= "foobar" (run-cmd-in-dir "python" "poetry" "pytest" "smoketest.py"))))))

19
python/pyproject.toml Normal file
View file

@ -0,0 +1,19 @@
[tool.poetry]
name = "smoketest"
version = "0.1.0"
description = "Smoketest to see if python tooling is functioning"
authors = ["Peter Tillemans <pti@snamellit.com>"]
license = "GPL2"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
requests = "^2.31.0"
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

15
python/smoketest.py Normal file
View file

@ -0,0 +1,15 @@
import requests
# get the response from google.com
def google_response_status():
response = requests.get("https://google.com")
return response.status_code
def test_google_response_status():
assert google_response_status() == 200
if __name__ == "__main__":
print(google_response_status())

25
test/cmd_test.clj Normal file
View file

@ -0,0 +1,25 @@
(ns cmd-test
(:require
[babashka.process :as p]
[testoperenv.cmd :refer [cmd-ok? run-cmd run-cmd-in-dir]]))
(require '[clojure.test :refer [deftest is testing]])
(deftest test-cmd-ok?
(testing "cmd-ok? returns true when exit code is 0"
(is (cmd-ok? {:exit 0})))
(testing "cmd-ok? returns false when exit code is not 0"
(is (not (cmd-ok? {:exit 1})))))
(deftest test-run-cmd
(testing "run-cmd returns stdout when exit code is 0"
(is (= "foobar" (run-cmd "echo" "-n" "foobar"))))
(testing "run-cmd throws exception when exit code is not 0"
(is (thrown? clojure.lang.ExceptionInfo (run-cmd "false")))))
(deftest test-run-cmd-in-dir
(testing "run-cmd-in-dir changes directory"
(is (= "python" (run-cmd-in-dir "python" "bash" "-c" "basename $(pwd)"))))
(testing "run-cmd-in-dir restores directory"
(is (= "testoperenv" (run-cmd "bash" "-c" "basename $(pwd)")))))