-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathuac_test.go
60 lines (49 loc) · 1.35 KB
/
uac_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
package ldsview
import (
"bytes"
"crypto/md5"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func NewTestEntities() []Entity {
entityLines := strings.Split(EntityStr, "\n")[1:]
entity := BuildEntity(entityLines)
return []Entity{entity}
}
func TestUACPrint(t *testing.T) {
t.Run("prints correct sorted output", func(t *testing.T) {
want := "b5106b8639687bb965a84af85e69113a"
buffer := &bytes.Buffer{}
UACPrint(buffer)
got := fmt.Sprintf("%x", md5.Sum(buffer.Bytes()))
assert.Equal(t, want, got)
})
}
func TestUACParse(t *testing.T) {
t.Run("parses and calculates the correct values", func(t *testing.T) {
want := []string{"NORMAL_ACCOUNT", "SCRIPT"}
got, err := UACParse("513")
assert.Equal(t, want, got)
assert.Nil(t, err)
})
t.Run("returns an error when invalid input is passed", func(t *testing.T) {
got, err := UACParse("I AM NOT A NUMBER!")
assert.Nil(t, got)
assert.NotNil(t, err)
})
}
func TestUACSearch(t *testing.T) {
entities := NewTestEntities()
t.Run("returns a correct entity when there is a match preset", func(t *testing.T) {
got := UACSearch(&entities, 512)
want := entities
assert.ElementsMatch(t, want, got)
})
t.Run("returns no entity when no match is preset", func(t *testing.T) {
got := UACSearch(&entities, 513)
want := make([]Entity, 0)
assert.ElementsMatch(t, want, got)
})
}