|
| 1 | +# Copyright 2019 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"Test serialization of tftest instances" |
| 16 | + |
| 17 | +import pytest |
| 18 | +import tftest |
| 19 | +import pickle |
| 20 | + |
| 21 | + |
| 22 | +def assert_pickle_flow(obj): |
| 23 | + """Ensures instance is the same after being pickled""" |
| 24 | + pickled_obj = pickle.dumps(obj) |
| 25 | + pickled_obj = pickle.loads(pickled_obj) |
| 26 | + assert isinstance(pickled_obj, type(obj)) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture(scope="module") |
| 30 | +def tf(fixtures_dir): |
| 31 | + tf = tftest.TerraformTest("plan_no_resource_changes", fixtures_dir) |
| 32 | + tf.setup() |
| 33 | + return tf |
| 34 | + |
| 35 | + |
| 36 | +def test_setup(fixtures_dir): |
| 37 | + tf = tftest.TerraformTest("plan_no_resource_changes", fixtures_dir) |
| 38 | + expected = tf.setup() |
| 39 | + assert_pickle_flow(expected) |
| 40 | + |
| 41 | + |
| 42 | +def test_plan(tf): |
| 43 | + expected = tf.plan(output=True) |
| 44 | + assert_pickle_flow(expected) |
| 45 | + |
| 46 | + |
| 47 | +def test_apply(tf): |
| 48 | + expected = tf.apply() |
| 49 | + assert_pickle_flow(expected) |
| 50 | + |
| 51 | + |
| 52 | +def test_output(tf): |
| 53 | + expected = tf.output() |
| 54 | + assert_pickle_flow(expected) |
| 55 | + |
| 56 | + |
| 57 | +def test_state_pull(tf): |
| 58 | + expected = tf.state_pull() |
| 59 | + assert_pickle_flow(expected) |
0 commit comments