This repository has been archived by the owner on Aug 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestcases_test.go
105 lines (93 loc) · 2.79 KB
/
testcases_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
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
// Copyright 2017 Tom Thorogood. All rights reserved.
// Use of this source code is governed by a Modified
// BSD License that can be found in the LICENSE file.
package bindata
import (
"crypto/sha512"
"flag"
"fmt"
"math/rand"
"os"
"reflect"
"github.com/tmthrgd/go-bindata/internal/identifier"
)
var testCases = map[string]func(*GenerateOptions){
"default": func(*GenerateOptions) {},
"old-default": func(o *GenerateOptions) {
*o = GenerateOptions{
Package: "main",
MemCopy: true,
Compress: true,
Metadata: true,
AssetDir: true,
Restore: true,
DecompressOnce: true,
}
},
"debug": func(o *GenerateOptions) { o.Debug = true },
"dev": func(o *GenerateOptions) { o.Dev = true },
"tags": func(o *GenerateOptions) { o.Tags = "!x" },
"package": func(o *GenerateOptions) { o.Package = "test" },
"compress": func(o *GenerateOptions) { o.Compress = true },
"copy": func(o *GenerateOptions) { o.MemCopy = true },
"metadata": func(o *GenerateOptions) { o.Metadata = true },
"decompress-once": func(o *GenerateOptions) {
o.Compress = true
o.DecompressOnce = true
},
"hash-unchanged": func(o *GenerateOptions) {
o.Hash = sha512.New()
},
"hash-dir": func(o *GenerateOptions) {
o.Hash = sha512.New()
o.HashFormat = DirHash
},
"hash-suffix": func(o *GenerateOptions) {
o.Hash = sha512.New()
o.HashFormat = NameHashSuffix
},
"hash-hashext": func(o *GenerateOptions) {
o.Hash = sha512.New()
o.HashFormat = HashWithExt
},
"hash-enc-b32": func(o *GenerateOptions) {
o.Hash = sha512.New()
o.HashEncoding = Base32Hash
o.HashFormat = DirHash
},
"hash-enc-b64": func(o *GenerateOptions) {
o.Hash = sha512.New()
o.HashEncoding = Base64Hash
o.HashFormat = DirHash
},
"hash-copy": func(o *GenerateOptions) {
o.MemCopy = true
o.Hash = sha512.New()
},
"asset-dir": func(o *GenerateOptions) { o.AssetDir = true },
}
var randTestCases = flag.Uint("randtests", 25, "the number of random test cases to add")
func setupTestCases() {
t := reflect.TypeOf(GenerateOptions{})
for i := uint(0); i < *randTestCases; i++ {
rand := rand.New(rand.NewSource(int64(i)))
v, ok := sizedValue(t, rand, complexSize)
if !ok {
panic("sizedValue failed")
}
vo := v.Addr().Interface().(*GenerateOptions)
vo.Package = identifier.Identifier(vo.Package)
vo.Mode &= os.ModePerm
vo.Metadata = vo.Metadata && (vo.Mode == 0 || vo.ModTime == 0)
vo.HashFormat = HashFormat(int(uint(vo.HashFormat) % uint(HashWithExt+1)))
vo.HashEncoding = HashEncoding(int(uint(vo.HashEncoding) % uint(Base64Hash+1)))
vo.Restore = vo.Restore && vo.AssetDir
if vo.Package == "" {
vo.Package = "main"
}
if vo.Debug || vo.Dev {
vo.Hash = nil
}
testCases[fmt.Sprintf("random-#%d", i+1)] = func(o *GenerateOptions) { *o = *vo }
}
}