-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_test.ts
140 lines (118 loc) · 3.92 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { assertEquals, assertStrictEquals, assertThrows, assertThrowsAsync } from "https://deno.land/std@0.65.0/testing/asserts.ts";
import { loadEnv } from "./src/dotenv.ts";
////////////////////////////////////////////////////////////////////////////////
interface IEnvStructure {
VARIABLE : boolean;
ANOTHER_TEST : string;
ANOTHER_TEST_2 : string;
ANOTHER_TEST_3 : number;
}
Deno.test( {
name : "Testing .env - Basic structure",
fn : async () => {
const mockStructure : IEnvStructure = {
VARIABLE : false,
ANOTHER_TEST : "some first text",
ANOTHER_TEST_2 : "some second text",
ANOTHER_TEST_3 : 3.14159
};
const env = await loadEnv<IEnvStructure>( {
envPath : "./examples/.env"
} );
assertEquals( mockStructure.VARIABLE, env.VARIABLE, "Expected VARIABLE to be same" );
assertEquals( mockStructure.ANOTHER_TEST, env.ANOTHER_TEST, "Expected ANOTHER_TEST to be same with single quotes" );
assertEquals( mockStructure.ANOTHER_TEST_2, env.ANOTHER_TEST_2, "Expected ANOTHER_TEST_2 to be same with double quotes" );
assertEquals( mockStructure.ANOTHER_TEST_3, env.ANOTHER_TEST_3, "Expected ANOTHER_TEST_3 float to be same" );
},
sanitizeResources : false,
sanitizeOps : false
} );
////////////////////////////////////////////////////////////////////////////////
interface IEnvMultilineStructure {
SECURITY : {
KEY : string;
};
}
Deno.test( {
name : "Testing .env-multiline - Multiline structure",
fn : async () => {
const mockStructure : IEnvMultilineStructure = {
SECURITY : {
KEY : `-----BEGIN RSA PRIVATE KEY TEST GENERATED-----
MIIBOgIBAAJBAJlxzvqoDGaanSXkyQdtUVxD/4HTA6DNoODdVn2yHh8n+1XS4dGq
Caqw8v491mOUioI48zxc+fWJndJz2NIU8CUCAwEAAQJAEt+hwsj6xYANBkUuyOAU
WtHuUoye7J9+Q0pWQh2vgMtbBO5wGnmtirQ0vqNve48J6xQjtnRG8CX2o/AIyCKL
gQIhAPtybm8kCgE/reekg46zbfvInu+9im9R8qP00V5q0r5hAiEAnDkXn+d2jnzN
5jLh0JCI9b5lLNtlmYUa9+Zg4BYroEUCIFemWwKZAHfQ99EAku9icptLIsQVQTVu
znMCuxz7hbzhAiBGzAjMypSL1jtpSz3Syu2GkJZBUdwlSpECL0FPzDxREQIhAOgt
0tiMRwonS5uc/sliUnOF1/c47gfcbaJavVSFtqZF
-----END RSA PRIVATE KEY TEST GENERATED-----`
}
};
const env = await loadEnv<IEnvMultilineStructure>( {
envPath : "./examples/.env-multiline"
} );
assertStrictEquals( mockStructure.SECURITY.KEY, env.SECURITY.KEY, "Expected SECURITY:KEY RSA keys to be same" );
},
sanitizeResources : false,
sanitizeOps : false
} );
////////////////////////////////////////////////////////////////////////////////
interface IEnvJSONStructure {
data : {
_id : string;
index : number;
guid : string;
isActive : boolean;
balance : string;
picture : string;
friends : Array<{
id : number;
name : string;
}>
};
}
Deno.test( {
name : "Testing .env-json - JSON structure",
fn : async () => {
const env = await loadEnv<IEnvJSONStructure>( {
envPath : "./examples/.env-json"
} );
assertStrictEquals( "5f43aa365114a7f64db74b83", env.data._id );
assertStrictEquals( true, env.data.isActive );
assertEquals( 3, env.data.friends.length, "Expected data:friends to have 3 items" );
assertEquals( "Sabrina Willis", env.data.friends[ 1 ].name, "Expected data:friends[1].name to be Sabrina Willis" );
},
sanitizeResources : false,
sanitizeOps : false
} );
////////////////////////////////////////////////////////////////////////////////
interface IEnvNamespaceStructure {
VARIABLE : boolean;
MySecretDatabase : {
host : string;
port : string;
password : string;
},
MyAnotherSecretDatabase : {
host : string;
port : string;
password : string;
},
Test: {
StringWithNumbers: string
}
}
Deno.test( {
name : "Testing .env.namespaces - Namespace structure",
fn : async () => {
const env = await loadEnv<IEnvNamespaceStructure>( {
envPath : "./examples/.env-namespaces"
} );
assertEquals( false, env.VARIABLE );
assertEquals( "won't tell you", env.MyAnotherSecretDatabase.password );
assertEquals( "5b54534877d09fc7024b6e9695783ea1", env.Test.StringWithNumbers );
},
sanitizeResources : false,
sanitizeOps : false
} );