summaryrefslogtreecommitdiff
path: root/tests/gobang.go
blob: a03e8bcf47271bc781fcf5975d14995c2c3c8e05 (plain) (blame)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
package gobang

import (
	"bytes"
	"crypto/sha1"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"hash"
	"log/slog"
	"os"
	"time"
)



type pbkdfTestVector struct {
	password string
	salt     string
	iter     int
	output   []byte
}

// Test vectors from RFC 6070, http://tools.ietf.org/html/rfc6070
var sha1TestVectors = []pbkdfTestVector {
	{
		"password",
		"salt",
		1,
		[]byte {
			0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
			0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
			0x2f, 0xe0, 0x37, 0xa6,
		},
	},
	{
		"password",
		"salt",
		2,
		[]byte{
			0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c,
			0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
			0xd8, 0xde, 0x89, 0x57,
		},
	},
	{
		"password",
		"salt",
		4096,
		[]byte{
			0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
			0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
			0x65, 0xa4, 0x29, 0xc1,
		},
	},
	// // This one takes too long
	// {
	// 	"password",
	// 	"salt",
	// 	16777216,
	// 	[]byte {
	// 		0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4,
	// 		0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c,
	// 		0x26, 0x34, 0xe9, 0x84,
	// 	},
	// },
	{
		"passwordPASSWORDpassword",
		"saltSALTsaltSALTsaltSALTsaltSALTsalt",
		4096,
		[]byte{
			0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
			0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
			0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
			0x38,
		},
	},
	{
		"pass\000word",
		"sa\000lt",
		4096,
		[]byte{
			0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
			0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3,
		},
	},
}

// Test vectors from
// http://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
var sha256TestVectors = []pbkdfTestVector {
	{
		"password",
		"salt",
		1,
		[]byte {
			0x12, 0x0f, 0xb6, 0xcf, 0xfc, 0xf8, 0xb3, 0x2c,
			0x43, 0xe7, 0x22, 0x52, 0x56, 0xc4, 0xf8, 0x37,
			0xa8, 0x65, 0x48, 0xc9,
		},
	},
	{
		"password",
		"salt",
		2,
		[]byte {
			0xae, 0x4d, 0x0c, 0x95, 0xaf, 0x6b, 0x46, 0xd3,
			0x2d, 0x0a, 0xdf, 0xf9, 0x28, 0xf0, 0x6d, 0xd0,
			0x2a, 0x30, 0x3f, 0x8e,
		},
	},
	{
		"password",
		"salt",
		4096,
		[]byte {
			0xc5, 0xe4, 0x78, 0xd5, 0x92, 0x88, 0xc8, 0x41,
			0xaa, 0x53, 0x0d, 0xb6, 0x84, 0x5c, 0x4c, 0x8d,
			0x96, 0x28, 0x93, 0xa0,
		},
	},
	{
		"passwordPASSWORDpassword",
		"saltSALTsaltSALTsaltSALTsaltSALTsalt",
		4096,
		[]byte {
			0x34, 0x8c, 0x89, 0xdb, 0xcb, 0xd3, 0x2b, 0x2f,
			0x32, 0xd8, 0x14, 0xb8, 0x11, 0x6e, 0x84, 0xcf,
			0x2b, 0x17, 0x34, 0x7e, 0xbc, 0x18, 0x00, 0x18,
			0x1c,
		},
	},
	{
		"pass\000word",
		"sa\000lt",
		4096,
		[]byte {
			0x89, 0xb6, 0x9d, 0x05, 0x16, 0xf8, 0x29, 0x89,
			0x3c, 0x69, 0x62, 0x26, 0x65, 0x0a, 0x86, 0x87,
		},
	},
}

func testHash(h func() hash.Hash, hashName string, vectors []pbkdfTestVector) {
	for i, v := range vectors {
		out := _PBKDF2Key(
			[]byte(v.password),
			[]byte(v.salt),
			v.iter,
			len(v.output),
			h,
		)
		AssertEqualI(i, out, v.output)
	}
}

func test__PBKDF() {
	TestStart("_PBKDF()")

	Testing("HMAC with SHA1", func() {
		testHash(sha1.New, "SHA1", sha1TestVectors)
	})

	Testing("HMAC with SHA256", func() {
		testHash(sha256.New, "SHA256", sha256TestVectors)
	})
}

type scryptTestVector struct {
	password string
	salt     string
	N, r, p  int
	output   []byte
}

var good = []scryptTestVector {
	{
		"password",
		"salt",
		2, 10, 10,
		[]byte {
			0x48, 0x2c, 0x85, 0x8e, 0x22, 0x90, 0x55, 0xe6, 0x2f,
			0x41, 0xe0, 0xec, 0x81, 0x9a, 0x5e, 0xe1, 0x8b, 0xdb,
			0x87, 0x25, 0x1a, 0x53, 0x4f, 0x75, 0xac, 0xd9, 0x5a,
			0xc5, 0xe5, 0xa, 0xa1, 0x5f,
		},
	},
	{
		"password",
		"salt",
		16, 100, 100,
		[]byte {
			0x88, 0xbd, 0x5e, 0xdb, 0x52, 0xd1, 0xdd, 0x0, 0x18,
			0x87, 0x72, 0xad, 0x36, 0x17, 0x12, 0x90, 0x22, 0x4e,
			0x74, 0x82, 0x95, 0x25, 0xb1, 0x8d, 0x73, 0x23, 0xa5,
			0x7f, 0x91, 0x96, 0x3c, 0x37,
		},
	},
	{
		"this is a long \000 password",
		"and this is a long \000 salt",
		16384, 8, 1,
		[]byte {
			0xc3, 0xf1, 0x82, 0xee, 0x2d, 0xec, 0x84, 0x6e, 0x70,
			0xa6, 0x94, 0x2f, 0xb5, 0x29, 0x98, 0x5a, 0x3a, 0x09,
			0x76, 0x5e, 0xf0, 0x4c, 0x61, 0x29, 0x23, 0xb1, 0x7f,
			0x18, 0x55, 0x5a, 0x37, 0x07, 0x6d, 0xeb, 0x2b, 0x98,
			0x30, 0xd6, 0x9d, 0xe5, 0x49, 0x26, 0x51, 0xe4, 0x50,
			0x6a, 0xe5, 0x77, 0x6d, 0x96, 0xd4, 0x0f, 0x67, 0xaa,
			0xee, 0x37, 0xe1, 0x77, 0x7b, 0x8a, 0xd5, 0xc3, 0x11,
			0x14, 0x32, 0xbb, 0x3b, 0x6f, 0x7e, 0x12, 0x64, 0x40,
			0x18, 0x79, 0xe6, 0x41, 0xae,
		},
	},
	{
		"p",
		"s",
		2, 1, 1,
		[]byte {
			0x48, 0xb0, 0xd2, 0xa8, 0xa3, 0x27, 0x26, 0x11, 0x98,
			0x4c, 0x50, 0xeb, 0xd6, 0x30, 0xaf, 0x52,
		},
	},

	{
		"",
		"",
		16, 1, 1,
		[]byte {
			0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20, 0x3b,
			0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97, 0xf1, 0x6b,
			0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8, 0xdf, 0xdf, 0xfa,
			0x3f, 0xed, 0xe2, 0x14, 0x42, 0xfc, 0xd0, 0x06, 0x9d,
			0xed, 0x09, 0x48, 0xf8, 0x32, 0x6a, 0x75, 0x3a, 0x0f,
			0xc8, 0x1f, 0x17, 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d,
			0x36, 0x28, 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89,
			0x06,
		},
	},
	{
		"password",
		"NaCl",
		1024, 8, 16,
		[]byte {
			0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00, 0x78,
			0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe, 0x7c, 0x6a,
			0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30, 0xe7, 0x73, 0x76,
			0x63, 0x4b, 0x37, 0x31, 0x62, 0x2e, 0xaf, 0x30, 0xd9,
			0x2e, 0x22, 0xa3, 0x88, 0x6f, 0xf1, 0x09, 0x27, 0x9d,
			0x98, 0x30, 0xda, 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83,
			0xee, 0x6d, 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06,
			0x40,
		},
	},
	{
		"pleaseletmein", "SodiumChloride",
		16384, 8, 1,
		[]byte {
			0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48, 0x46,
			0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb, 0xfd, 0xa8,
			0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e, 0xa9, 0xb5, 0x43,
			0xf6, 0x54, 0x5d, 0xa1, 0xf2, 0xd5, 0x43, 0x29, 0x55,
			0x61, 0x3f, 0x0f, 0xcf, 0x62, 0xd4, 0x97, 0x05, 0x24,
			0x2a, 0x9a, 0xf9, 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65,
			0x1e, 0x40, 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58,
			0x87,
		},
	},
	// // Disabled: needs 1 GiB RAM and takes too long for a simple test.
	// {
	// 	"pleaseletmein", "SodiumChloride",
	// 	1048576, 8, 1,
	// 	[]byte{
	// 		0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae, 0xad,
	// 		0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81, 0xec, 0x56,
	// 		0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d, 0xab, 0xe5, 0xee,
	// 		0x98, 0x20, 0xad, 0xaa, 0x47, 0x8e, 0x56, 0xfd, 0x8f,
	// 		0x4b, 0xa5, 0xd0, 0x9f, 0xfa, 0x1c, 0x6d, 0x92, 0x7c,
	// 		0x40, 0xf4, 0xc3, 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9,
	// 		0x52, 0xfb, 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41,
	// 		0xa4,
	// 	},
	// },
}

const halfMax = maxInt / 2
var bad = []scryptTestVector {
	{"p", "s", 0, 1, 1, nil},                    // N == 0
	{"p", "s", 1, 1, 1, nil},                    // N == 1
	{"p", "s", 7, 8, 1, nil},                    // N is not power of 2
	{"p", "s", 16, halfMax, halfMax, nil},       // p * r too large
}

func test_scrypt() {
	TestStart("scrypt()")

	Testing("good hashes", func() {
		for i, v := range good {
			k, err := scrypt(
				[]byte(v.password),
				[]byte(v.salt),
				v.N,
				v.r,
				v.p,
				len(v.output),
			)
			ErrorIf(err)
			AssertEqualI(i, k, v.output)
		}
	})

	Testing("bad hashes", func() {
		for _, v := range bad {
			_, err := scrypt(
				[]byte(v.password),
				[]byte(v.salt),
				v.N,
				v.r,
				v.p,
				32,
			)
			ErrorNil(err)
		}
	})

	Testing("example value", func() {
		const expected = "lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M="
		// DO NOT use this salt value; generate your own random salt.
		// 8 bytes is a good length.
		salt := []byte{0xc8, 0x28, 0xf2, 0x58, 0xa7, 0x6a, 0xad, 0x7b}

		dk, err := scrypt(
			[]byte("some password"),
			salt,
			1<<15,
			8,
			1,
			32,
		)
		ErrorIf(err)

		given := base64.StdEncoding.EncodeToString(dk)
		AssertEqual(given, expected)
	})
}

func test_Random() {
	TestStart("Random()")

	Testing("we get the desired output size", func() {
		for i := 0; i < 100; i++ {
			buffer := Random(i)
			AssertEqual(len(buffer), i)
		}
	})
}

func test_Salt() {
	TestStart("Salt()")

	Testing("we generate a random salt of a fixed size", func() {
		salt := Salt()
		AssertEqual(len(salt), scryptSaltMinLength)

		var buffer [scryptSaltMinLength * 2]byte
		hex.Encode(buffer[:], salt)
		fmt.Fprintf(os.Stderr, "%s ", string(buffer[:]))
	})
}

func test_Hash() {
	TestStart("Hash()")

	Testing("same input, same output", func() {
		password := Random(16)
		salt := Salt()
		hash1 := Hash(password, salt)
		hash2 := Hash(password, salt)
		AssertEqual(hash1, hash2)
	})
}

func test_newUUIDFrom() {
	TestStart("newUUIDFrom()")

	Testing("same UUID from same input", func() {
		for i := 0; i < 100; i++ {
			var b [uuidByteCount]byte
			buffer := Random(uuidByteCount)
			now := time.Now().UnixNano()

			lastV7Time = now + 1
			copy(b[:], buffer)
			uuid1 := newUUIDFrom(b, now)

			lastV7Time = now + 1
			copy(b[:], buffer)
			uuid2 := newUUIDFrom(b, now)

			AssertEqual(uuid1, uuid2)
		}
	})
}

func test_NewUUID() {
	TestStart("NewUUID()")

	Testing("we can generate UUID values", func() {
		var uuid UUID = NewUUID()
		AssertEqual(len(uuid.bytes), uuidByteCount)
	})
}

func test_UUIDString() {
	TestStart("UUID.String()")

	Testing("simple example values", func() {
		uuids := []UUID {
			UUID {
				bytes: [uuidByteCount]byte {
					0, 0, 0, 0, 0, 0, 0, 0,
					0, 0, 0, 0, 0, 0, 0, 0,
				},
			},
			UUID {
				bytes: [uuidByteCount]byte {
					0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
					10, 11, 12, 13, 14, 15,
				},
			},
			UUID {
				bytes: [uuidByteCount]byte {
					222, 222, 222, 222, 222, 222, 222, 222,
					222, 222, 222, 222, 222, 222, 222, 222,
				},
			},
			UUID {
				bytes: [uuidByteCount]byte {
					255, 255, 255, 255, 255, 255, 255, 255,
					255, 255, 255, 255, 255, 255, 255, 255,
				},
			},
		}

		strs := []string {
			"00000000-0000-0000-0000-000000000000",
			"00010203-0405-0607-0809-0a0b0c0d0e0f",
			"dededede-dede-dede-dede-dededededede",
			"ffffffff-ffff-ffff-ffff-ffffffffffff",
		}

		for i := range uuids {
			AssertEqual(uuids[i].String(), strs[i])
		}
	})
}

func test_ParseUUID() {
	TestStart("ParseUUID()")

	Testing("UUID -> string -> UUID round trip", func() {
		for i := 0; i < 100; i++ {
			uuid0 := NewUUID()
			uuid1, err := ParseUUID(uuid0.String())
			ErrorIf(err)
			AssertEqual(uuid1, uuid0)
		}
	})

	Testing("errors we detect", func() {
		var err error

		_, err = ParseUUID("")
		AssertEqual(err, badUUIDLengthError)

		_, err = ParseUUID("---000000000000000000000000000000000")
		AssertEqual(err, badUUIDDashCountError)

		_, err = ParseUUID("----00000000000000000000000000000000")
		AssertEqual(err, badUUIDDashPositionError)

		_, err = ParseUUID("00000000-0000-0000-0000-00000000000g")
		AssertEqual(err, hex.InvalidByteError('g'))

		_, err = ParseUUID("00000000-0000-0000-0000-000000000000")
		ErrorIf(err)
	})
}

func test_showColour() {
	TestStart("showColour()")

	const NAME = "NO_COLOUR"
	savedEnvvar := os.Getenv(NAME)

	Testing("true when envvar is unset", func() {
		ErrorIf(os.Unsetenv(NAME))
		AssertEqual(showColour(), true)
	})

	Testing("true when envvar is empty", func() {
		ErrorIf(os.Setenv(NAME, ""))
		AssertEqual(showColour(), true)
	})

	Testing("false otherwise", func() {
		ErrorIf(os.Setenv(NAME, "1"))
		AssertEqual(showColour(), false)
	})

	ErrorIf(os.Setenv(NAME, savedEnvvar))
}

func test_levelFromString() {
	TestStart("levelFromString()")

	values := []string { "NONE", "ERROR", "WARNING", "INFO", "DEBUG" }
	Testing("ok for expected values", func() {
		for _, s := range values {
			var fallback logLevel = 123
			theLevel := levelFromString(s, fallback)
			notFallback :=
				theLevel >= LevelNone &&
				theLevel <= LevelDebug &&
				theLevel != fallback
			AssertEqual(notFallback, true)
		}
	})

	Testing("fallback for unexpected values", func() {
		var fallback logLevel = 123
		theLevel := levelFromString(string(Random(10)), fallback)
		AssertEqual(theLevel, fallback)
	})
}

func test_setLogLevel() {
	TestStart("setLogLevel()")

	const NAME = "LOG_LEVEL"
	savedEnvvar := os.Getenv(NAME)
	savedValue  := level
	var fallbackValue logLevel = 123

	Testing("noop when envvar is unset", func() {
		ErrorIf(os.Unsetenv(NAME))
		level = fallbackValue

		setLogLevel()

		AssertEqual(level, fallbackValue)
	})

	Testing("noop when envvar is empty", func() {
		ErrorIf(os.Setenv(NAME, ""))
		level = fallbackValue

		setLogLevel()

		AssertEqual(level, fallbackValue)
	})

	Testing("update variable otherwise", func() {
		ErrorIf(os.Setenv(NAME, "DEBUG"))
		level = fallbackValue

		setLogLevel()

		AssertEqual(level, LevelDebug)
	})

	ErrorIf(os.Setenv(NAME, savedEnvvar))
	level = savedValue
}

func test_setMetric() {
	TestStart("setMetric()")

	const NAME = "NO_METRIC"
	savedEnvvar := os.Getenv(NAME)
	savedValue  := emitMetric

	Testing("noop when envvar is unset", func() {
		ErrorIf(os.Unsetenv(NAME))
		emitMetric = true

		setMetric()

		AssertEqual(emitMetric, true)
	})

	Testing("noop when envvar is empty", func() {
		ErrorIf(os.Setenv(NAME, ""))
		emitMetric = true

		setMetric()

		AssertEqual(emitMetric, true)
	})

	Testing("make variable false otherwise", func() {
		ErrorIf(os.Setenv(NAME, "1"))
		emitMetric = true

		setMetric()

		AssertEqual(emitMetric, false)
	})

	ErrorIf(os.Setenv(NAME, savedEnvvar))
	emitMetric = savedValue
}

func test_FatalIf() {
	TestStart("FatalIf()")

	Testing("noop on nil value", func() {
		FatalIf(nil)
	})
}

func test_Assert() {
	TestStart("Assert()")

	Testing("noop on true value", func() {
		Assert(true, "")
	})
}

func test_setHostname() {
	TestStart("setHostname()")

	Testing("it assigns the value to the global variable", func() {
		name, _ := os.Hostname()
		hostname = ""
		setHostname()
		AssertEqual(hostname, name)
	})
}

func TestSetLoggerOutput() {
	return
	type entry struct {
		msg  string `json:"msg"`
		aKey string `json:"a-key"`
	}
	var e entry
	var buf bytes.Buffer
	slog.Error("the message", "a-key", "a-value")

	s := buf.String()
	// fmt.Println(s)
	// fmt.Println(e)
	err := json.Unmarshal([]byte(s), &e)
	if err != nil {
		// t.Fail()
		// Mmain()
	}
	if e.msg != "the message" {
		// t.Fail()
	}
	fmt.Println(1)
	// fmt.Println(e)
}

func t1() {
	test__PBKDF()
}

func t2() {
	test_scrypt()
}

func t3() {
	test_Hash()
}

func t4() {
	test_Random()
	test_Salt()
	test_newUUIDFrom()
	test_NewUUID()
	test_UUIDString()
	test_ParseUUID()
	test_showColour()
	test_levelFromString()
	test_setLogLevel()
	test_setMetric()
	test_FatalIf()
	test_Assert()
	test_setHostname()
}

func MainTest() {
	arg := ""
	if len(os.Args) > 1 {
		arg = os.Args[1]
	}

	switch arg {
		case "1":
			t1()
		case "2":
			t2()
		case "3":
			t3()
		case "4":
			t4()
		default:
			t1()
			t2()
			t3()
			t4()
	}
}