|
| 1 | +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"). You may |
| 4 | +// not use this file except in compliance with the License. A copy of the |
| 5 | +// License is located at |
| 6 | +// |
| 7 | +// http://aws.amazon.com/apache2.0/ |
| 8 | +// |
| 9 | +// or in the "license" file accompanying this file. This file is distributed |
| 10 | +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | +// express or implied. See the License for the specific language governing |
| 12 | +// permissions and limitations under the License. |
| 13 | + |
| 14 | +package selector_test |
| 15 | + |
| 16 | +import ( |
| 17 | + "regexp" |
| 18 | + "strings" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/aws/amazon-ec2-instance-selector/pkg/selector" |
| 22 | + h "github.com/aws/amazon-ec2-instance-selector/pkg/test" |
| 23 | +) |
| 24 | + |
| 25 | +// Tests |
| 26 | + |
| 27 | +func TestMarshalIndent(t *testing.T) { |
| 28 | + cpuArch := "x86_64" |
| 29 | + allowRegex := "^abc$" |
| 30 | + denyRegex := "^zyx$" |
| 31 | + |
| 32 | + filters := selector.Filters{ |
| 33 | + AllowList: regexp.MustCompile(allowRegex), |
| 34 | + DenyList: regexp.MustCompile(denyRegex), |
| 35 | + CPUArchitecture: &cpuArch, |
| 36 | + } |
| 37 | + out, err := filters.MarshalIndent("", " ") |
| 38 | + outStr := string(out) |
| 39 | + h.Ok(t, err) |
| 40 | + h.Assert(t, strings.Contains(outStr, "AllowList") && strings.Contains(outStr, allowRegex), "Does not include AllowList regex string") |
| 41 | + h.Assert(t, strings.Contains(outStr, "DenyList") && strings.Contains(outStr, denyRegex), "Does not include DenyList regex string") |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +func TestMarshalIndent_nil(t *testing.T) { |
| 46 | + denyRegex := "^zyx$" |
| 47 | + |
| 48 | + filters := selector.Filters{ |
| 49 | + AllowList: nil, |
| 50 | + DenyList: regexp.MustCompile(denyRegex), |
| 51 | + } |
| 52 | + out, err := filters.MarshalIndent("", " ") |
| 53 | + outStr := string(out) |
| 54 | + h.Ok(t, err) |
| 55 | + h.Assert(t, strings.Contains(outStr, "AllowList") && strings.Contains(outStr, "null"), "Does not include AllowList null entry") |
| 56 | + h.Assert(t, strings.Contains(outStr, "DenyList") && strings.Contains(outStr, denyRegex), "Does not include DenyList regex string") |
| 57 | + |
| 58 | +} |
0 commit comments