{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.CloudFront.Types.TestResult
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudFront.Types.TestResult where

import Amazonka.CloudFront.Types.FunctionSummary
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains the result of testing a CloudFront function with
-- @TestFunction@.
--
-- /See:/ 'newTestResult' smart constructor.
data TestResult = TestResult'
  { -- | The amount of time that the function took to run as a percentage of the
    -- maximum allowed time. For example, a compute utilization of 35 means
    -- that the function completed in 35% of the maximum allowed time.
    TestResult -> Maybe Text
computeUtilization :: Prelude.Maybe Prelude.Text,
    -- | Contains the log lines that the function wrote (if any) when running the
    -- test.
    TestResult -> Maybe [Text]
functionExecutionLogs :: Prelude.Maybe [Prelude.Text],
    -- | The event object returned by the function. For more information about
    -- the structure of the event object, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html Event object structure>
    -- in the /Amazon CloudFront Developer Guide/.
    TestResult -> Maybe Text
functionOutput :: Prelude.Maybe Prelude.Text,
    -- | Contains configuration information and metadata about the CloudFront
    -- function that was tested.
    TestResult -> Maybe FunctionSummary
functionSummary :: Prelude.Maybe FunctionSummary,
    -- | If the result of testing the function was an error, this field contains
    -- the error message.
    TestResult -> Maybe Text
functionErrorMessage :: Prelude.Maybe Prelude.Text
  }
  deriving (TestResult -> TestResult -> Bool
(TestResult -> TestResult -> Bool)
-> (TestResult -> TestResult -> Bool) -> Eq TestResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestResult -> TestResult -> Bool
$c/= :: TestResult -> TestResult -> Bool
== :: TestResult -> TestResult -> Bool
$c== :: TestResult -> TestResult -> Bool
Prelude.Eq, ReadPrec [TestResult]
ReadPrec TestResult
Int -> ReadS TestResult
ReadS [TestResult]
(Int -> ReadS TestResult)
-> ReadS [TestResult]
-> ReadPrec TestResult
-> ReadPrec [TestResult]
-> Read TestResult
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestResult]
$creadListPrec :: ReadPrec [TestResult]
readPrec :: ReadPrec TestResult
$creadPrec :: ReadPrec TestResult
readList :: ReadS [TestResult]
$creadList :: ReadS [TestResult]
readsPrec :: Int -> ReadS TestResult
$creadsPrec :: Int -> ReadS TestResult
Prelude.Read, Int -> TestResult -> ShowS
[TestResult] -> ShowS
TestResult -> String
(Int -> TestResult -> ShowS)
-> (TestResult -> String)
-> ([TestResult] -> ShowS)
-> Show TestResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestResult] -> ShowS
$cshowList :: [TestResult] -> ShowS
show :: TestResult -> String
$cshow :: TestResult -> String
showsPrec :: Int -> TestResult -> ShowS
$cshowsPrec :: Int -> TestResult -> ShowS
Prelude.Show, (forall x. TestResult -> Rep TestResult x)
-> (forall x. Rep TestResult x -> TestResult) -> Generic TestResult
forall x. Rep TestResult x -> TestResult
forall x. TestResult -> Rep TestResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TestResult x -> TestResult
$cfrom :: forall x. TestResult -> Rep TestResult x
Prelude.Generic)

-- |
-- Create a value of 'TestResult' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'computeUtilization', 'testResult_computeUtilization' - The amount of time that the function took to run as a percentage of the
-- maximum allowed time. For example, a compute utilization of 35 means
-- that the function completed in 35% of the maximum allowed time.
--
-- 'functionExecutionLogs', 'testResult_functionExecutionLogs' - Contains the log lines that the function wrote (if any) when running the
-- test.
--
-- 'functionOutput', 'testResult_functionOutput' - The event object returned by the function. For more information about
-- the structure of the event object, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html Event object structure>
-- in the /Amazon CloudFront Developer Guide/.
--
-- 'functionSummary', 'testResult_functionSummary' - Contains configuration information and metadata about the CloudFront
-- function that was tested.
--
-- 'functionErrorMessage', 'testResult_functionErrorMessage' - If the result of testing the function was an error, this field contains
-- the error message.
newTestResult ::
  TestResult
newTestResult :: TestResult
newTestResult =
  TestResult' :: Maybe Text
-> Maybe [Text]
-> Maybe Text
-> Maybe FunctionSummary
-> Maybe Text
-> TestResult
TestResult'
    { $sel:computeUtilization:TestResult' :: Maybe Text
computeUtilization = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionExecutionLogs:TestResult' :: Maybe [Text]
functionExecutionLogs = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:functionOutput:TestResult' :: Maybe Text
functionOutput = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionSummary:TestResult' :: Maybe FunctionSummary
functionSummary = Maybe FunctionSummary
forall a. Maybe a
Prelude.Nothing,
      $sel:functionErrorMessage:TestResult' :: Maybe Text
functionErrorMessage = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The amount of time that the function took to run as a percentage of the
-- maximum allowed time. For example, a compute utilization of 35 means
-- that the function completed in 35% of the maximum allowed time.
testResult_computeUtilization :: Lens.Lens' TestResult (Prelude.Maybe Prelude.Text)
testResult_computeUtilization :: (Maybe Text -> f (Maybe Text)) -> TestResult -> f TestResult
testResult_computeUtilization = (TestResult -> Maybe Text)
-> (TestResult -> Maybe Text -> TestResult)
-> Lens TestResult TestResult (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe Text
computeUtilization :: Maybe Text
$sel:computeUtilization:TestResult' :: TestResult -> Maybe Text
computeUtilization} -> Maybe Text
computeUtilization) (\s :: TestResult
s@TestResult' {} Maybe Text
a -> TestResult
s {$sel:computeUtilization:TestResult' :: Maybe Text
computeUtilization = Maybe Text
a} :: TestResult)

-- | Contains the log lines that the function wrote (if any) when running the
-- test.
testResult_functionExecutionLogs :: Lens.Lens' TestResult (Prelude.Maybe [Prelude.Text])
testResult_functionExecutionLogs :: (Maybe [Text] -> f (Maybe [Text])) -> TestResult -> f TestResult
testResult_functionExecutionLogs = (TestResult -> Maybe [Text])
-> (TestResult -> Maybe [Text] -> TestResult)
-> Lens TestResult TestResult (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe [Text]
functionExecutionLogs :: Maybe [Text]
$sel:functionExecutionLogs:TestResult' :: TestResult -> Maybe [Text]
functionExecutionLogs} -> Maybe [Text]
functionExecutionLogs) (\s :: TestResult
s@TestResult' {} Maybe [Text]
a -> TestResult
s {$sel:functionExecutionLogs:TestResult' :: Maybe [Text]
functionExecutionLogs = Maybe [Text]
a} :: TestResult) ((Maybe [Text] -> f (Maybe [Text])) -> TestResult -> f TestResult)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> TestResult
-> f TestResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The event object returned by the function. For more information about
-- the structure of the event object, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html Event object structure>
-- in the /Amazon CloudFront Developer Guide/.
testResult_functionOutput :: Lens.Lens' TestResult (Prelude.Maybe Prelude.Text)
testResult_functionOutput :: (Maybe Text -> f (Maybe Text)) -> TestResult -> f TestResult
testResult_functionOutput = (TestResult -> Maybe Text)
-> (TestResult -> Maybe Text -> TestResult)
-> Lens TestResult TestResult (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe Text
functionOutput :: Maybe Text
$sel:functionOutput:TestResult' :: TestResult -> Maybe Text
functionOutput} -> Maybe Text
functionOutput) (\s :: TestResult
s@TestResult' {} Maybe Text
a -> TestResult
s {$sel:functionOutput:TestResult' :: Maybe Text
functionOutput = Maybe Text
a} :: TestResult)

-- | Contains configuration information and metadata about the CloudFront
-- function that was tested.
testResult_functionSummary :: Lens.Lens' TestResult (Prelude.Maybe FunctionSummary)
testResult_functionSummary :: (Maybe FunctionSummary -> f (Maybe FunctionSummary))
-> TestResult -> f TestResult
testResult_functionSummary = (TestResult -> Maybe FunctionSummary)
-> (TestResult -> Maybe FunctionSummary -> TestResult)
-> Lens
     TestResult
     TestResult
     (Maybe FunctionSummary)
     (Maybe FunctionSummary)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe FunctionSummary
functionSummary :: Maybe FunctionSummary
$sel:functionSummary:TestResult' :: TestResult -> Maybe FunctionSummary
functionSummary} -> Maybe FunctionSummary
functionSummary) (\s :: TestResult
s@TestResult' {} Maybe FunctionSummary
a -> TestResult
s {$sel:functionSummary:TestResult' :: Maybe FunctionSummary
functionSummary = Maybe FunctionSummary
a} :: TestResult)

-- | If the result of testing the function was an error, this field contains
-- the error message.
testResult_functionErrorMessage :: Lens.Lens' TestResult (Prelude.Maybe Prelude.Text)
testResult_functionErrorMessage :: (Maybe Text -> f (Maybe Text)) -> TestResult -> f TestResult
testResult_functionErrorMessage = (TestResult -> Maybe Text)
-> (TestResult -> Maybe Text -> TestResult)
-> Lens TestResult TestResult (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe Text
functionErrorMessage :: Maybe Text
$sel:functionErrorMessage:TestResult' :: TestResult -> Maybe Text
functionErrorMessage} -> Maybe Text
functionErrorMessage) (\s :: TestResult
s@TestResult' {} Maybe Text
a -> TestResult
s {$sel:functionErrorMessage:TestResult' :: Maybe Text
functionErrorMessage = Maybe Text
a} :: TestResult)

instance Core.FromXML TestResult where
  parseXML :: [Node] -> Either String TestResult
parseXML [Node]
x =
    Maybe Text
-> Maybe [Text]
-> Maybe Text
-> Maybe FunctionSummary
-> Maybe Text
-> TestResult
TestResult'
      (Maybe Text
 -> Maybe [Text]
 -> Maybe Text
 -> Maybe FunctionSummary
 -> Maybe Text
 -> TestResult)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe [Text]
      -> Maybe Text -> Maybe FunctionSummary -> Maybe Text -> TestResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ComputeUtilization")
      Either
  String
  (Maybe [Text]
   -> Maybe Text -> Maybe FunctionSummary -> Maybe Text -> TestResult)
-> Either String (Maybe [Text])
-> Either
     String
     (Maybe Text -> Maybe FunctionSummary -> Maybe Text -> TestResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"FunctionExecutionLogs"
                      Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Text]))
-> Either String (Maybe [Text])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Text])
-> [Node] -> Either String (Maybe [Text])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either
  String
  (Maybe Text -> Maybe FunctionSummary -> Maybe Text -> TestResult)
-> Either String (Maybe Text)
-> Either
     String (Maybe FunctionSummary -> Maybe Text -> TestResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"FunctionOutput")
      Either String (Maybe FunctionSummary -> Maybe Text -> TestResult)
-> Either String (Maybe FunctionSummary)
-> Either String (Maybe Text -> TestResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe FunctionSummary)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"FunctionSummary")
      Either String (Maybe Text -> TestResult)
-> Either String (Maybe Text) -> Either String TestResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"FunctionErrorMessage")

instance Prelude.Hashable TestResult

instance Prelude.NFData TestResult