Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 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 | // http://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 | package android |
| 16 | |
| 17 | import "testing" |
| 18 | |
| 19 | // Make sure that FixturePreparer instances are only called once per fixture and in the order in |
| 20 | // which they were added. |
| 21 | func TestFixtureDedup(t *testing.T) { |
| 22 | list := []string{} |
| 23 | |
| 24 | appendToList := func(s string) FixturePreparer { |
| 25 | return FixtureModifyConfig(func(_ Config) { |
| 26 | list = append(list, s) |
| 27 | }) |
| 28 | } |
| 29 | |
| 30 | preparer1 := appendToList("preparer1") |
| 31 | preparer2 := appendToList("preparer2") |
| 32 | preparer3 := appendToList("preparer3") |
| 33 | preparer4 := appendToList("preparer4") |
| 34 | |
Paul Duffin | a560d5a | 2021-02-28 01:38:51 +0000 | [diff] [blame] | 35 | preparer1Then2 := GroupFixturePreparers(preparer1, preparer2) |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 36 | |
Paul Duffin | a560d5a | 2021-02-28 01:38:51 +0000 | [diff] [blame] | 37 | preparer2Then1 := GroupFixturePreparers(preparer2, preparer1) |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 38 | |
| 39 | buildDir := "build" |
| 40 | factory := NewFixtureFactory(&buildDir, preparer1, preparer2, preparer1, preparer1Then2) |
| 41 | |
| 42 | extension := factory.Extend(preparer4, preparer2) |
| 43 | |
| 44 | extension.Fixture(t, preparer1, preparer2, preparer2Then1, preparer3) |
| 45 | |
Paul Duffin | 3d0ddff | 2021-03-12 12:20:59 +0000 | [diff] [blame^] | 46 | AssertDeepEquals(t, "preparers called in wrong order", |
Paul Duffin | 3581612 | 2021-02-24 01:49:52 +0000 | [diff] [blame] | 47 | []string{"preparer1", "preparer2", "preparer4", "preparer3"}, list) |
| 48 | } |