@@ -2,6 +2,12 @@ import { expect } from "chai";
22import * as tf from "./terraform" ;
33
44describe ( "terraform iac" , ( ) => {
5+ interface TestInterface {
6+ camelCaseField ?: string ;
7+ field ?: number ;
8+ other ?: number ;
9+ }
10+
511 describe ( "expr" , ( ) => {
612 it ( "should return an HCLExpression object" , ( ) => {
713 expect ( tf . expr ( "var.foo" ) ) . to . deep . equal ( {
@@ -13,29 +19,40 @@ describe("terraform iac", () => {
1319
1420 describe ( "copyField" , ( ) => {
1521 it ( "should copy a field to attributes, converting its name to lower snake case" , ( ) => {
16- const attrs : any = { } ;
17- tf . copyField ( attrs , { camelCaseField : "value" } , "camelCaseField" ) ;
22+ const attrs : Record < string , tf . Value > = { } ;
23+ const test : TestInterface = { camelCaseField : "value" } ;
24+ tf . copyField ( attrs , test , "camelCaseField" ) ;
1825 expect ( attrs ) . to . deep . equal ( { camel_case_field : "value" } ) ;
1926 } ) ;
2027
2128 it ( "should optionally transform the field value" , ( ) => {
22- const attrs : any = { } ;
23- tf . copyField ( attrs , { field : 42 } , "field" , ( v ) => ( v as number ) * 2 ) ;
29+ const attrs : Record < string , tf . Value > = { } ;
30+ const test : TestInterface = { field : 42 } ;
31+ tf . copyField ( attrs , test , "field" , ( v ) => ( v as number ) * 2 ) ;
2432 expect ( attrs ) . to . deep . equal ( { field : 84 } ) ;
2533 } ) ;
2634
2735 it ( "should not set anything if the source field is missing" , ( ) => {
28- const attrs : any = { } ;
29- tf . copyField ( attrs , { other : 123 } as any , "field" ) ;
36+ const attrs : Record < string , tf . Value > = { } ;
37+ const test : TestInterface = { other : 123 } ;
38+ tf . copyField ( attrs , test , "field" ) ;
3039 expect ( attrs ) . to . deep . equal ( { } ) ;
3140 } ) ;
3241 } ) ;
3342
3443 describe ( "renameField" , ( ) => {
3544 it ( "should copy a field to a different attribute name" , ( ) => {
36- const attrs : any = { } ;
37- tf . renameField ( attrs , { field : "value" } , "new_field" , "field" ) ;
38- expect ( attrs ) . to . deep . equal ( { new_field : "value" } ) ;
45+ const attrs : Record < string , tf . Value > = { } ;
46+ const test : TestInterface = { field : 42 } ;
47+ tf . renameField ( attrs , test , "new_field" , "field" ) ;
48+ expect ( attrs ) . to . deep . equal ( { new_field : 42 } ) ;
49+ } ) ;
50+
51+ it ( "should not set anything if the source field is missing" , ( ) => {
52+ const attrs : Record < string , tf . Value > = { } ;
53+ const test : TestInterface = { other : 123 } ;
54+ tf . renameField ( attrs , test , "new_field" , "field" ) ;
55+ expect ( attrs ) . to . deep . equal ( { } ) ;
3956 } ) ;
4057 } ) ;
4158
0 commit comments