<commit_before>(ns vignette.storage.s3-test
  (:require (vignette.storage [protocols :refer :all]
                              [s3 :refer :all]
                              [common :as sc])
            (vignette.util [byte-streams :refer :all])
            [pantomime.mime :refer (mime-type-of)]
            [aws.sdk.s3 :as s3]
            [midje.sweet :refer :all]
            [clojure.java.io :as io])
  (:import [com.amazonaws.services.s3.model AmazonS3Exception]))

(facts :s3 :get-object
  (get-object (create-s3-object-storage ..creds..) "bucket" "a/ab/image.jpg") => ..object..
  (provided
    (safe-get-object ..creds.. "bucket" "a/ab/image.jpg") => {:content ..stream..
                                                              :metadata {:content-length ..length.. :content-type ..content-type..}}
    (read-byte-stream ..stream.. ..length..) => ..bytes..
    (sc/create-storage-object ..bytes.. ..content-type.. ..length..) => ..object..)

  (get-object (create-s3-object-storage ..creds..) "bucket" "a/ab/image.jpg") => falsey
  (provided
    (s3/get-object ..creds.. "bucket" "a/ab/image.jpg") => {})

  (get-object (create-s3-object-storage ..creds..) "bucket" "d/do/does-not-exist.jpg") => falsey
  (provided
    (s3/get-object ..creds.. "bucket" "d/do/does-not-exist.jpg") =throws=> (let [e (AmazonS3Exception. "foo")]
                                                                             (.setStatusCode e 404)
                                                                             e)))

(facts :s3 :put-object
  (put-object (create-s3-object-storage ..creds..) ..resource.. "bucket" "a/ab/image.jpg") => ..response..
  (provided
    (mime-type-of ..resource..) => ..content-type..
    (s3/put-object ..creds.. "bucket" "a/ab/image.jpg" ..resource.. {:content-type ..content-type..}) => ..response..)

  ; this may not be realistic. we'll probably get an error before we get nil
  (put-object (create-s3-object-storage ..creds..) ..resource.. "bucket" "a/ab/image.jpg") => nil
  (provided
    (mime-type-of ..resource..) => ..content-type..
    (s3/put-object ..creds.. "bucket" "a/ab/image.jpg" ..resource.. {:content-type ..content-type..}) => nil))<commit_msg>Fix the unit tests.<commit_after>(ns vignette.storage.s3-test
  (:require (vignette.storage [protocols :refer :all]
                              [s3 :refer :all]
                              [common :as sc])
            (vignette.util [byte-streams :refer :all])
            [pantomime.mime :refer (mime-type-of)]
            [aws.sdk.s3 :as s3]
            [midje.sweet :refer :all]
            [clojure.java.io :as io])
  (:import [com.amazonaws.services.s3.model AmazonS3Exception]))

(facts :s3 :get-object
  (get-object (create-s3-object-storage ..creds..) "bucket" "a/ab/image.jpg") => ..object..
  (provided
    (safe-get-object ..creds.. "bucket" "a/ab/image.jpg") => {:content ..stream..
                                                              :metadata {:content-length ..length.. :content-type ..content-type..}}
    (sc/create-storage-object ..stream.. ..content-type.. ..length..) => ..object..)

  (get-object (create-s3-object-storage ..creds..) "bucket" "a/ab/image.jpg") => falsey
  (provided
    (s3/get-object ..creds.. "bucket" "a/ab/image.jpg") => {})

  (get-object (create-s3-object-storage ..creds..) "bucket" "d/do/does-not-exist.jpg") => falsey
  (provided
    (s3/get-object ..creds.. "bucket" "d/do/does-not-exist.jpg") =throws=> (let [e (AmazonS3Exception. "foo")]
                                                                             (.setStatusCode e 404)
                                                                             e)))

(facts :s3 :put-object
  (put-object (create-s3-object-storage ..creds..) ..resource.. "bucket" "a/ab/image.jpg") => ..response..
  (provided
    (mime-type-of ..resource..) => ..content-type..
    (s3/put-object ..creds.. "bucket" "a/ab/image.jpg" ..resource.. {:content-type ..content-type..}) => ..response..)

  ; this may not be realistic. we'll probably get an error before we get nil
  (put-object (create-s3-object-storage ..creds..) ..resource.. "bucket" "a/ab/image.jpg") => nil
  (provided
    (mime-type-of ..resource..) => ..content-type..
    (s3/put-object ..creds.. "bucket" "a/ab/image.jpg" ..resource.. {:content-type ..content-type..}) => nil))
{'fraction_non_alphanumeric': 0.1976075454336324, 'fraction_numerical': 0.00966183574879227, 'mean_word_length': 1.7380352644836272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1537016', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1394, 'n_words': 294}