-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from takaishi/chore/index-import-block
fix: failure parsing to string like module.foo["hoge"]
- Loading branch information
Showing
2 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package tfclean | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2/hclparse" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestApp_cutImportBlock(t *testing.T) { | ||
type fields struct { | ||
hclParser *hclparse.Parser | ||
CLI *CLI | ||
} | ||
type args struct { | ||
data []byte | ||
to string | ||
id string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want []byte | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "", | ||
fields: fields{}, | ||
args: args{ | ||
data: []byte(` | ||
aaa | ||
import { | ||
id = "resource_id" | ||
to = module.foo.hoge | ||
} | ||
bbb | ||
`), | ||
to: "module.foo.hoge", | ||
id: "resource_id", | ||
}, | ||
want: []byte("\naaa\nbbb\n"), | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "", | ||
fields: fields{}, | ||
args: args{ | ||
data: []byte(` | ||
aaa | ||
import { | ||
id = "resource_id" | ||
to = module.foo["hoge"] | ||
} | ||
bbb | ||
`), | ||
to: "module.foo[\"hoge\"]", | ||
id: "resource_id", | ||
}, | ||
want: []byte("\naaa\nbbb\n"), | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
app := &App{ | ||
hclParser: tt.fields.hclParser, | ||
CLI: tt.fields.CLI, | ||
} | ||
got, err := app.cutImportBlock(tt.args.data, tt.args.to, tt.args.id) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("cutImportBlock() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("cutImportBlock() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |