|
1 | 1 | package rules
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - hcl "github.com/hashicorp/hcl/v2" |
5 |
| - "github.com/terraform-linters/tflint-plugin-sdk/helper" |
6 | 4 | "testing"
|
7 | 5 | "time"
|
| 6 | + |
| 7 | + hcl "github.com/hashicorp/hcl/v2" |
| 8 | + "github.com/terraform-linters/tflint-plugin-sdk/helper" |
8 | 9 | )
|
9 | 10 |
|
10 | 11 | func Test_AwsLambdaFunctionEndOfSupport(t *testing.T) {
|
11 |
| - type caseStudy struct { |
| 12 | + cases := []struct { |
12 | 13 | Name string
|
13 | 14 | Content string
|
| 15 | + Now time.Time |
14 | 16 | Expected helper.Issues
|
15 |
| - } |
16 |
| - eosRuntimes := map[string]time.Time{ |
17 |
| - "nodejs10.x": time.Date(2021, time.July, 30, 0, 0, 0, 0, time.UTC), |
18 |
| - "ruby2.5": time.Date(2021, time.July, 30, 0, 0, 0, 0, time.UTC), |
19 |
| - "python2.7": time.Date(2021, time.July, 15, 0, 0, 0, 0, time.UTC), |
20 |
| - "dotnetcore2.1": time.Date(2021, time.September, 20, 0, 0, 0, 0, time.UTC), |
21 |
| - } |
22 |
| - var cases []caseStudy |
23 |
| - now := time.Now().UTC() |
24 |
| - for runtime, eosDate := range eosRuntimes { |
25 |
| - if now.Before(eosDate) { |
26 |
| - continue |
27 |
| - } |
28 |
| - study := caseStudy{ |
29 |
| - Name: runtime + " end of support", |
| 17 | + }{ |
| 18 | + { |
| 19 | + Name: "EOS", |
30 | 20 | Content: `
|
31 | 21 | resource "aws_lambda_function" "function" {
|
32 | 22 | function_name = "test_function"
|
33 | 23 | role = "test_role"
|
34 |
| - runtime = "` + runtime + `" |
| 24 | + runtime = "nodejs10.x" |
35 | 25 | }
|
36 | 26 | `,
|
| 27 | + Now: time.Date(2021, time.August, 10, 0, 0, 0, 0, time.UTC), |
37 | 28 | Expected: helper.Issues{
|
38 | 29 | {
|
39 | 30 | Rule: NewAwsLambdaFunctionDeprecatedRuntimeRule(),
|
40 |
| - Message: "The \"" + runtime + "\" runtime has reached the end of support", |
| 31 | + Message: "The \"nodejs10.x\" runtime has reached the end of support", |
41 | 32 | Range: hcl.Range{
|
42 | 33 | Filename: "resource.tf",
|
43 | 34 | Start: hcl.Pos{Line: 5, Column: 12},
|
44 |
| - End: hcl.Pos{Line: 5, Column: len(runtime) + 14}, |
| 35 | + End: hcl.Pos{Line: 5, Column: 24}, |
45 | 36 | },
|
46 | 37 | },
|
47 | 38 | },
|
48 |
| - } |
49 |
| - cases = append(cases, study) |
50 |
| - } |
51 |
| - eolRuntimes := map[string]time.Time{ |
52 |
| - "dotnetcore1.0": time.Date(2019, time.July, 30, 0, 0, 0, 0, time.UTC), |
53 |
| - "dotnetcore2.0": time.Date(2019, time.May, 30, 0, 0, 0, 0, time.UTC), |
54 |
| - "nodejs": time.Date(2016, time.October, 31, 0, 0, 0, 0, time.UTC), |
55 |
| - "nodejs4.3": time.Date(2020, time.March, 06, 0, 0, 0, 0, time.UTC), |
56 |
| - "nodejs4.3-edge": time.Date(2019, time.April, 30, 0, 0, 0, 0, time.UTC), |
57 |
| - "nodejs6.10": time.Date(2019, time.August, 12, 0, 0, 0, 0, time.UTC), |
58 |
| - "nodejs8.10": time.Date(2020, time.March, 06, 0, 0, 0, 0, time.UTC), |
59 |
| - "nodejs10.x": time.Date(2021, time.August, 30, 0, 0, 0, 0, time.UTC), |
60 |
| - "ruby2.5": time.Date(2021, time.August, 30, 0, 0, 0, 0, time.UTC), |
61 |
| - "python2.7": time.Date(2021, time.September, 30, 0, 0, 0, 0, time.UTC), |
62 |
| - "dotnetcore2.1": time.Date(2021, time.October, 30, 0, 0, 0, 0, time.UTC), |
63 |
| - } |
64 |
| - for runtime, eolDate := range eolRuntimes { |
65 |
| - if now.Before(eolDate) { |
66 |
| - continue |
67 |
| - } |
68 |
| - study := caseStudy{ |
69 |
| - Name: runtime + " end of life", |
| 39 | + }, |
| 40 | + { |
| 41 | + Name: "EOF", |
70 | 42 | Content: `
|
71 | 43 | resource "aws_lambda_function" "function" {
|
72 | 44 | function_name = "test_function"
|
73 | 45 | role = "test_role"
|
74 |
| - runtime = "` + runtime + `" |
| 46 | + runtime = "nodejs10.x" |
75 | 47 | }
|
76 | 48 | `,
|
| 49 | + Now: time.Date(2021, time.September, 1, 0, 0, 0, 0, time.UTC), |
77 | 50 | Expected: helper.Issues{
|
78 | 51 | {
|
79 | 52 | Rule: NewAwsLambdaFunctionDeprecatedRuntimeRule(),
|
80 |
| - Message: "The \"" + runtime + "\" runtime has reached the end of life", |
| 53 | + Message: "The \"nodejs10.x\" runtime has reached the end of life", |
81 | 54 | Range: hcl.Range{
|
82 | 55 | Filename: "resource.tf",
|
83 | 56 | Start: hcl.Pos{Line: 5, Column: 12},
|
84 |
| - End: hcl.Pos{Line: 5, Column: len(runtime) + 14}, |
| 57 | + End: hcl.Pos{Line: 5, Column: 24}, |
85 | 58 | },
|
86 | 59 | },
|
87 | 60 | },
|
88 |
| - } |
89 |
| - cases = append(cases, study) |
| 61 | + }, |
| 62 | + { |
| 63 | + Name: "Live", |
| 64 | + Content: ` |
| 65 | +resource "aws_lambda_function" "function" { |
| 66 | + function_name = "test_function" |
| 67 | + role = "test_role" |
| 68 | + runtime = "nodejs10.x" |
| 69 | +} |
| 70 | +`, |
| 71 | + Now: time.Date(2021, time.June, 25, 0, 0, 0, 0, time.UTC), |
| 72 | + Expected: helper.Issues{}, |
| 73 | + }, |
90 | 74 | }
|
91 | 75 |
|
92 | 76 | rule := NewAwsLambdaFunctionDeprecatedRuntimeRule()
|
93 | 77 |
|
94 | 78 | for _, tc := range cases {
|
| 79 | + rule.Now = tc.Now |
| 80 | + |
95 | 81 | runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content})
|
96 | 82 |
|
97 | 83 | if err := rule.Check(runner); err != nil {
|
|
0 commit comments