Skip to content

Commit 713246f

Browse files
committed
Added three more function tests for messages from package comm.
1 parent b144a97 commit 713246f

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed

comm/message_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,121 @@ func TestParse(t *testing.T) {
165165
t.Fatalf("[comm.TestParse] marshalled6: Expected value 'this is a long payload' as payload but found: '%v'\n", msg6.Payload)
166166
}
167167
}
168+
169+
// TestParseOp executes a black-box unit test
170+
// on implemented ParseOp() function of messages.
171+
func TestParseOp(t *testing.T) {
172+
173+
// Test message strings.
174+
msg1 := "|"
175+
msg2 := "operation|payload"
176+
msg3 := "123op!|p$$$load|more|payload|v4lu3s"
177+
178+
op1, payload1, err := comm.ParseOp(msg1)
179+
if err != nil {
180+
t.Fatalf("[comm.TestParseOp] msg1: Expected nil error but received: '%v'", err)
181+
}
182+
183+
if op1 != "" {
184+
t.Fatalf("[comm.TestParseOp] msg1: Expected operation to be '' but found: '%s'", op1)
185+
}
186+
187+
if payload1 != "" {
188+
t.Fatalf("[comm.TestParseOp] msg1: Expected payload to be '' but found: '%s'", payload1)
189+
}
190+
191+
op2, payload2, err := comm.ParseOp(msg2)
192+
if err != nil {
193+
t.Fatalf("[comm.TestParseOp] msg2: Expected nil error but received: '%v'", err)
194+
}
195+
196+
if op2 != "operation" {
197+
t.Fatalf("[comm.TestParseOp] msg2: Expected operation to be 'operation' but found: '%s'", op2)
198+
}
199+
200+
if payload2 != "payload" {
201+
t.Fatalf("[comm.TestParseOp] msg2: Expected payload to be 'payload' but found: '%s'", payload2)
202+
}
203+
204+
op3, payload3, err := comm.ParseOp(msg3)
205+
if err != nil {
206+
t.Fatalf("[comm.TestParseOp] msg3: Expected nil error but received: '%v'", err)
207+
}
208+
209+
if op3 != "123op!" {
210+
t.Fatalf("[comm.TestParseOp] msg3: Expected operation to be '123op!' but found: '%s'", op3)
211+
}
212+
213+
if payload3 != "p$$$load|more|payload|v4lu3s" {
214+
t.Fatalf("[comm.TestParseOp] msg3: Expected payload to be 'p$$$load|more|payload|v4lu3s' but found: '%s'", payload3)
215+
}
216+
}
217+
218+
// TestParseCreate executes a black-box unit test
219+
// on implemented ParseCreate() function of messages.
220+
func TestParseCreate(t *testing.T) {
221+
222+
// user1, University.Thesis, University.Thesis, ae3daa63-4d50-4ea5-baa4-d5f780e05302, ""
223+
create1 := "user1|VW5pdmVyc2l0eS5UaGVzaXM=|VW5pdmVyc2l0eS5UaGVzaXM=;ae3daa63-4d50-4ea5-baa4-d5f780e05302"
224+
225+
createParsed1, err := comm.ParseCreate(create1)
226+
if err != nil {
227+
t.Fatalf("[comm.TestParseCreate] create1: Expected nil error but received: '%v'", err)
228+
}
229+
230+
if createParsed1.User != "user1" {
231+
t.Fatalf("[comm.TestParseCreate] create1: Expected User to be 'user1' but found: '%v'", createParsed1.User)
232+
}
233+
234+
if createParsed1.Mailbox != "University.Thesis" {
235+
t.Fatalf("[comm.TestParseCreate] create1: Expected Mailbox to be 'University.Thesis' but found: '%v'", createParsed1.Mailbox)
236+
}
237+
238+
if createParsed1.AddMailbox.Value != "University.Thesis" {
239+
t.Fatalf("[comm.TestParseCreate] create1: Expected AddMailbox.Value to be 'University.Thesis' but found: '%v'", createParsed1.AddMailbox.Value)
240+
}
241+
242+
if createParsed1.AddMailbox.Tag != "ae3daa63-4d50-4ea5-baa4-d5f780e05302" {
243+
t.Fatalf("[comm.TestParseCreate] create1: Expected AddMailbox.Tag to be 'ae3daa63-4d50-4ea5-baa4-d5f780e05302' but found: '%v'", createParsed1.AddMailbox.Tag)
244+
}
245+
246+
if createParsed1.AddMailbox.Contents != "" {
247+
t.Fatalf("[comm.TestParseCreate] create1: Expected AddMailbox.Contents to be '' but found: '%v'", createParsed1.AddMailbox.Contents)
248+
}
249+
}
250+
251+
// TestParseDelete executes a black-box unit test
252+
// on implemented ParseDelete() function of messages.
253+
func TestParseDelete(t *testing.T) {
254+
255+
// user1, University.Thesis, University.Thesis, 76e18257-3687-41f3-8c94-9a7b4d1a9799, ""
256+
delete1 := "user1|VW5pdmVyc2l0eS5UaGVzaXM=|VW5pdmVyc2l0eS5UaGVzaXM=;76e18257-3687-41f3-8c94-9a7b4d1a9799"
257+
258+
deleteParsed1, err := comm.ParseDelete(delete1)
259+
if err != nil {
260+
t.Fatalf("[comm.TestParseDelete] delete1: Expected nil error but received: '%v'", err)
261+
}
262+
263+
if deleteParsed1.User != "user1" {
264+
t.Fatalf("[comm.TestParseDelete] delete1: Expected User to be 'user1' but found: '%v'", deleteParsed1.User)
265+
}
266+
267+
if deleteParsed1.Mailbox != "University.Thesis" {
268+
t.Fatalf("[comm.TestParseDelete] delete1: Expected Mailbox to be 'University.Thesis' but found: '%v'", deleteParsed1.Mailbox)
269+
}
270+
271+
for _, rmvMailbox := range deleteParsed1.RmvMailbox {
272+
273+
if rmvMailbox.Value != "University.Thesis" {
274+
t.Fatalf("[comm.TestParseDelete] delete1: Expected RmvMailbox.Value to be 'University.Thesis' but found: '%v'", rmvMailbox.Value)
275+
}
276+
277+
if rmvMailbox.Tag != "76e18257-3687-41f3-8c94-9a7b4d1a9799" {
278+
t.Fatalf("[comm.TestParseDelete] delete1: Expected RmvMailbox.Tag to be '76e18257-3687-41f3-8c94-9a7b4d1a9799' but found: '%v'", rmvMailbox.Tag)
279+
}
280+
281+
if rmvMailbox.Contents != "" {
282+
t.Fatalf("[comm.TestParseDelete] delete1: Expected RmvMailbox.Contents to be '' but found: '%v'", rmvMailbox.Contents)
283+
}
284+
}
285+
}

config/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestLoadConfig(t *testing.T) {
2121
}
2222

2323
// Now load a valid config.
24-
config, err := config.LoadConfig("../test-config.toml")
24+
conf, err := config.LoadConfig("../test-config.toml")
2525
if err != nil {
2626
t.Fatalf("[config.TestLoadConfig] Expected success while loading 'test-config.toml' but received: '%s'\n", err.Error())
2727
}
@@ -36,7 +36,7 @@ func TestLoadConfig(t *testing.T) {
3636
absCertLoc := filepath.Join(absPlutoPath, "private/public-distributor-cert.pem")
3737

3838
// Check for test success.
39-
if config.Distributor.PublicTLS.CertLoc != absCertLoc {
40-
t.Fatalf("[config.TestLoadConfig] Expected '%s' but received '%s'\n", absCertLoc, config.Distributor.PublicTLS.CertLoc)
39+
if conf.Distributor.PublicTLS.CertLoc != absCertLoc {
40+
t.Fatalf("[config.TestLoadConfig] Expected '%s' but received '%s'\n", absCertLoc, conf.Distributor.PublicTLS.CertLoc)
4141
}
4242
}

0 commit comments

Comments
 (0)