<commit_before>(ns clojure.digitalocean-expect.test
  (:require [digitalocean.droplet :refer :all]
            [environ.core :refer [env]]
            [expectations :refer [expect from-each]]))

(def nodes (droplets (env :digitalocean-client-id) (env :digitalocean-api-key)))
(def creds {:client (env :digitalocean-client-id) :key (env :digitalocean-api-key)})

(defn nodes-by-status [status]
  (droplets-with-status creds status))

(def stopped-nodes (nodes-by-status "stopped"))
(def active-nodes (nodes-by-status "active"))

(def DIGITALOCEAN-SIZES
  {:small  66
   :medium 62
   :large  60})

(def DIGITALOCEAN-LOCATIONS
  {:london       7
   :sanfrancisco 3})

(defn size-id [size id]
  (= (size DIGITALOCEAN-SIZES) id))

(defn small? [id] (size-id :small id))
(defn medium? [id] (size-id :medium id))
(defn large? [id] (size-id :large id))

(defn location-id [location region-id]
  (= (location DIGITALOCEAN-LOCATIONS) region-id))

(defn london? [region] (location-id :london region))
(defn sf? [region] (location-id :sanfrancisco region))

; not more than 100 nodes
(expect (< (count nodes) 100))

; check number of stopped nodes
(expect 0 (count stopped-nodes))

; check node with specific name
(expect (droplet-by-name creds "test-digitalocean"))

; check backups are enabled for all nodes
(expect true? (from-each
  [node nodes] (:backups_active node)))

; check private networks are enabled for all nodes
(expect (complement nil?) (from-each
  [node nodes] (:private_ip_address node)))

; only use prescribed sizes
(expect 0
  (count
    (remove large?
      (remove medium?
        (remove small? (map :size_id nodes))))))

; only use prescribed regions
(expect 0
  (count
    (remove london?
      (remove sf? (map :region_id nodes)))))

; no more than 2 large nodes
(expect (< (count (filter large? (map :size_id nodes))) 2))<commit_msg>another test for names<commit_after>(ns clojure.digitalocean-expect.test
  (:require [digitalocean.droplet :refer :all]
            [environ.core :refer [env]]
            [expectations :refer [expect from-each]]))

(def nodes (droplets (env :digitalocean-client-id) (env :digitalocean-api-key)))
(def creds {:client (env :digitalocean-client-id) :key (env :digitalocean-api-key)})

(defn nodes-by-status [status]
  (droplets-with-status creds status))

(def stopped-nodes (nodes-by-status "stopped"))
(def active-nodes (nodes-by-status "active"))

(def DIGITALOCEAN-SIZES
  {:small  66
   :medium 62
   :large  60})

(def DIGITALOCEAN-LOCATIONS
  {:london       7
   :sanfrancisco 3})

(defn size-id [size id]
  (= (size DIGITALOCEAN-SIZES) id))

(defn small? [id] (size-id :small id))
(defn medium? [id] (size-id :medium id))
(defn large? [id] (size-id :large id))

(defn location-id [location region-id]
  (= (location DIGITALOCEAN-LOCATIONS) region-id))

(defn london? [region] (location-id :london region))
(defn sf? [region] (location-id :sanfrancisco region))

(defn valid-name? [name]
  (re-matches #"test|staging|prod+-[a-z]+" name))

; not more than 100 nodes
(expect (< (count nodes) 100))

; check number of stopped nodes
(expect 0 (count stopped-nodes))

; check node with specific name
(expect (droplet-by-name creds "test-digitalocean"))

; check backups are enabled for all nodes
(expect true? (from-each
  [node nodes] (:backups_active node)))

; check private networks are enabled for all nodes
(expect (complement nil?) (from-each
  [node nodes] (:private_ip_address node)))

; only use prescribed sizes
(expect 0
  (count
    (remove large?
      (remove medium?
        (remove small? (map :size_id nodes))))))

; only use prescribed regions
(expect 0
  (count
    (remove london?
      (remove sf? (map :region_id nodes)))))

; no more than 2 large nodes
(expect (< (count (filter large? (map :size_id nodes))) 2))

; check names match prescribed pattern
(expect (every? valid-name? (map :name node)))
{'fraction_non_alphanumeric': 0.14481156427465153, 'fraction_numerical': 0.00980898296334538, 'mean_word_length': 4.146082337317397, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5514437', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1351, 'n_words': 421}