This repository was archived by the owner on Jun 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package lint
2+
3+ import (
4+ "testing"
5+ )
6+
7+ func Test_filesFromArgs (t * testing.T ) {
8+ tests := []struct {
9+ Filename string
10+ Want string
11+ }{
12+ {
13+ "testdata/01.tf" ,
14+ `{
15+ "provider": [
16+ {
17+ "google": [
18+ {
19+ "project": "my-project-id",
20+ "region": "us-central1"
21+ }
22+ ]
23+ }
24+ ]
25+ }` ,
26+ },
27+ {
28+ "testdata/02.tf" ,
29+ `{
30+ "provider": [
31+ {
32+ "google": [
33+ {
34+ "project": "my-project-id",
35+ "region": "us-central1"
36+ }
37+ ]
38+ },
39+ {
40+ "aws": [
41+ {
42+ "region": "us-east-1",
43+ "version": "~\u003e 2.0"
44+ }
45+ ]
46+ },
47+ {
48+ "google": [
49+ {
50+ "alias": "west",
51+ "project": "my-project-id",
52+ "region": "us-west1"
53+ }
54+ ]
55+ }
56+ ]
57+ }` ,
58+ },
59+ {
60+ "testdata/03.tf" ,
61+ `{
62+ "module": [
63+ {
64+ "foo": [
65+ {
66+ "array": [
67+ "val1",
68+ "val2"
69+ ],
70+ "bar": "baz"
71+ }
72+ ]
73+ }
74+ ]
75+ }` ,
76+ },
77+ {
78+ "testdata/04.tf" ,
79+ `{
80+ "resource": [
81+ {
82+ "google_project": [
83+ {
84+ "my_project": [
85+ {
86+ "name": "My Project",
87+ "org_id": "1234567",
88+ "project_id": "your-project-id"
89+ }
90+ ]
91+ }
92+ ]
93+ }
94+ ]
95+ }` ,
96+ },
97+ }
98+
99+ for _ , test := range tests {
100+ t .Run (test .Filename , func (t * testing.T ) {
101+ files , err := filesFromArgs ([]string {test .Filename })
102+ if err != nil {
103+ t .Fatalf ("unexpected error: %s" , err )
104+ }
105+ if len (files ) != 1 {
106+ t .Errorf ("unexpected files length: got %d, want 1" , len (files ))
107+ }
108+ got := string (files [0 ].Data )
109+ if got != test .Want {
110+ t .Errorf ("wrong result: got: %#v, want: %#v" , got , test .Want )
111+ }
112+ })
113+ }
114+ }
Original file line number Diff line number Diff line change 1+ provider "google" {
2+ project = " my-project-id"
3+ region = " us-central1"
4+ }
Original file line number Diff line number Diff line change 1+ provider "google" {
2+ project = " my-project-id"
3+ region = " us-central1"
4+ }
5+ provider "aws" {
6+ version = " ~> 2.0"
7+ region = " us-east-1"
8+ }
9+ provider "google" {
10+ project = " my-project-id"
11+ region = " us-west1"
12+ alias = " west"
13+ }
Original file line number Diff line number Diff line change 1+ module "foo" {
2+ bar = " baz"
3+
4+ array = [
5+ " val1" ,
6+ " val2" ,
7+ ]
8+ }
Original file line number Diff line number Diff line change 1+ resource "google_project" "my_project" {
2+ name = " My Project"
3+ project_id = " your-project-id"
4+ org_id = " 1234567"
5+ }
6+
You can’t perform that action at this time.
0 commit comments