forked from hugelgupf/u-root
-
Notifications
You must be signed in to change notification settings - Fork 7
/
passphrase_test.go
71 lines (66 loc) · 1.66 KB
/
passphrase_test.go
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
// Copyright 2018 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package passphrase
import (
"fmt"
"reflect"
"testing"
)
type RunTestCase struct {
name string
essid string
pass string
out string
err error
}
var (
essidStub = "stub"
shortPass = "aaaaaaa" // 7 chars
longPass = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // 64 chars
validPass = "aaaaaaaaaaaaaaaa" // 16 chars
correctOutput = `network={
ssid="stub"
#psk="aaaaaaaaaaaaaaaa"
psk=e270ba95a72c6d922e902f65dfa23315f7ba43b69debc75167254acd778f2fe9
}
`
runTestCases = []RunTestCase{
{
name: "No essid",
essid: "",
pass: validPass,
out: "",
err: fmt.Errorf("essid cannot be empty"),
},
{
name: "pass length is less than 8 chars",
essid: essidStub,
pass: shortPass,
out: "",
err: fmt.Errorf("Passphrase must be 8..63 characters"),
},
{
name: "pass length is more than 63 chars",
essid: essidStub,
pass: longPass,
out: "",
err: fmt.Errorf("Passphrase must be 8..63 characters"),
},
{
name: "Correct Input",
essid: essidStub,
pass: validPass,
out: correctOutput,
err: nil,
},
}
)
func TestRun(t *testing.T) {
for _, test := range runTestCases {
out, err := Run(test.essid, test.pass)
if !reflect.DeepEqual(err, test.err) || string(out) != test.out {
t.Errorf("TEST %s\ngot:[%v, %v]\nwant:[%v, %v]", test.name, err, string(out), test.err, string(test.out))
}
}
}