...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package app
17
18 import (
19 "testing"
20 )
21
22 func TestValidateTimestampServerURL(t *testing.T) {
23 type test struct {
24 caseDesc string
25 timestampServer string
26 expectSuccess bool
27 }
28
29 tests := []test{
30 {
31 caseDesc: "value not specified",
32 expectSuccess: false,
33 },
34 {
35 caseDesc: "valid timestamp_server value",
36 timestampServer: "http://localhost:3000",
37 expectSuccess: true,
38 },
39 {
40 caseDesc: "valid URL, invalid scheme",
41 timestampServer: "ldap://localhost:3000",
42 expectSuccess: false,
43 },
44 {
45 caseDesc: "invalid URL",
46 timestampServer: "hteeteepeeColonSlashSlashlocalhost:3000",
47 expectSuccess: false,
48 },
49 {
50 caseDesc: "local path",
51 timestampServer: "/localhost",
52 expectSuccess: false,
53 },
54 }
55
56 for _, tc := range tests {
57 if err := rootCmd.PersistentFlags().Set("timestamp_server", tc.timestampServer); (err == nil) != tc.expectSuccess {
58 t.Errorf("unexpected result in '%v': %v", tc.caseDesc, err)
59 }
60 }
61 }
62
View as plain text