{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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,
    -- | If the result of testing the function was an error, this field contains
    -- the error message.
    TestResult -> Maybe (Sensitive Text)
functionErrorMessage :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | Contains the log lines that the function wrote (if any) when running the
    -- test.
    TestResult -> Maybe (Sensitive [Text])
functionExecutionLogs :: Prelude.Maybe (Data.Sensitive [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 (Sensitive Text)
functionOutput :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | Contains configuration information and metadata about the CloudFront
    -- function that was tested.
    TestResult -> Maybe FunctionSummary
functionSummary :: Prelude.Maybe FunctionSummary
  }
  deriving (TestResult -> TestResult -> Bool
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, Int -> TestResult -> ShowS
[TestResult] -> ShowS
TestResult -> String
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. 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.
--
-- 'functionErrorMessage', 'testResult_functionErrorMessage' - If the result of testing the function was an error, this field contains
-- the error message.
--
-- '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.
newTestResult ::
  TestResult
newTestResult :: TestResult
newTestResult =
  TestResult'
    { $sel:computeUtilization:TestResult' :: Maybe Text
computeUtilization = forall a. Maybe a
Prelude.Nothing,
      $sel:functionErrorMessage:TestResult' :: Maybe (Sensitive Text)
functionErrorMessage = forall a. Maybe a
Prelude.Nothing,
      $sel:functionExecutionLogs:TestResult' :: Maybe (Sensitive [Text])
functionExecutionLogs = forall a. Maybe a
Prelude.Nothing,
      $sel:functionOutput:TestResult' :: Maybe (Sensitive Text)
functionOutput = forall a. Maybe a
Prelude.Nothing,
      $sel:functionSummary:TestResult' :: Maybe FunctionSummary
functionSummary = 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 :: Lens' TestResult (Maybe Text)
testResult_computeUtilization = 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)

-- | 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 :: Lens' TestResult (Maybe Text)
testResult_functionErrorMessage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe (Sensitive Text)
functionErrorMessage :: Maybe (Sensitive Text)
$sel:functionErrorMessage:TestResult' :: TestResult -> Maybe (Sensitive Text)
functionErrorMessage} -> Maybe (Sensitive Text)
functionErrorMessage) (\s :: TestResult
s@TestResult' {} Maybe (Sensitive Text)
a -> TestResult
s {$sel:functionErrorMessage:TestResult' :: Maybe (Sensitive Text)
functionErrorMessage = Maybe (Sensitive Text)
a} :: TestResult) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | 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 :: Lens' TestResult (Maybe [Text])
testResult_functionExecutionLogs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe (Sensitive [Text])
functionExecutionLogs :: Maybe (Sensitive [Text])
$sel:functionExecutionLogs:TestResult' :: TestResult -> Maybe (Sensitive [Text])
functionExecutionLogs} -> Maybe (Sensitive [Text])
functionExecutionLogs) (\s :: TestResult
s@TestResult' {} Maybe (Sensitive [Text])
a -> TestResult
s {$sel:functionExecutionLogs:TestResult' :: Maybe (Sensitive [Text])
functionExecutionLogs = Maybe (Sensitive [Text])
a} :: TestResult) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 (forall a. Iso' (Sensitive a) a
Data._Sensitive forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' TestResult (Maybe Text)
testResult_functionOutput = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestResult' {Maybe (Sensitive Text)
functionOutput :: Maybe (Sensitive Text)
$sel:functionOutput:TestResult' :: TestResult -> Maybe (Sensitive Text)
functionOutput} -> Maybe (Sensitive Text)
functionOutput) (\s :: TestResult
s@TestResult' {} Maybe (Sensitive Text)
a -> TestResult
s {$sel:functionOutput:TestResult' :: Maybe (Sensitive Text)
functionOutput = Maybe (Sensitive Text)
a} :: TestResult) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | Contains configuration information and metadata about the CloudFront
-- function that was tested.
testResult_functionSummary :: Lens.Lens' TestResult (Prelude.Maybe FunctionSummary)
testResult_functionSummary :: Lens' TestResult (Maybe FunctionSummary)
testResult_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)

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

instance Prelude.Hashable TestResult where
  hashWithSalt :: Int -> TestResult -> Int
hashWithSalt Int
_salt TestResult' {Maybe Text
Maybe (Sensitive [Text])
Maybe (Sensitive Text)
Maybe FunctionSummary
functionSummary :: Maybe FunctionSummary
functionOutput :: Maybe (Sensitive Text)
functionExecutionLogs :: Maybe (Sensitive [Text])
functionErrorMessage :: Maybe (Sensitive Text)
computeUtilization :: Maybe Text
$sel:functionSummary:TestResult' :: TestResult -> Maybe FunctionSummary
$sel:functionOutput:TestResult' :: TestResult -> Maybe (Sensitive Text)
$sel:functionExecutionLogs:TestResult' :: TestResult -> Maybe (Sensitive [Text])
$sel:functionErrorMessage:TestResult' :: TestResult -> Maybe (Sensitive Text)
$sel:computeUtilization:TestResult' :: TestResult -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
computeUtilization
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
functionErrorMessage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive [Text])
functionExecutionLogs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
functionOutput
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FunctionSummary
functionSummary

instance Prelude.NFData TestResult where
  rnf :: TestResult -> ()
rnf TestResult' {Maybe Text
Maybe (Sensitive [Text])
Maybe (Sensitive Text)
Maybe FunctionSummary
functionSummary :: Maybe FunctionSummary
functionOutput :: Maybe (Sensitive Text)
functionExecutionLogs :: Maybe (Sensitive [Text])
functionErrorMessage :: Maybe (Sensitive Text)
computeUtilization :: Maybe Text
$sel:functionSummary:TestResult' :: TestResult -> Maybe FunctionSummary
$sel:functionOutput:TestResult' :: TestResult -> Maybe (Sensitive Text)
$sel:functionExecutionLogs:TestResult' :: TestResult -> Maybe (Sensitive [Text])
$sel:functionErrorMessage:TestResult' :: TestResult -> Maybe (Sensitive Text)
$sel:computeUtilization:TestResult' :: TestResult -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
computeUtilization
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
functionErrorMessage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive [Text])
functionExecutionLogs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
functionOutput
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe FunctionSummary
functionSummary