@@ -10,6 +10,7 @@ the source. If not, see http://www.gnu.org/licenses/gpl-2.0.html.
10
10
package lookup
11
11
12
12
import (
13
+ "os"
13
14
"testing"
14
15
15
16
"github.com/stretchr/testify/suite"
@@ -48,6 +49,38 @@ func (s *LocalPGPTest) TestIsMatchFailsWithoutMatches() {
48
49
s .False (local .isMatch ("foo" , user ))
49
50
}
50
51
52
+ func (s * LocalPGPTest ) TestGnupgHomeOverride () {
53
+ os .Setenv ("GNUPGHOME" , "/foo" )
54
+ _ , err := NewLocalPGPService ()
55
+ s .EqualError (err , "stat /foo/pubring.gpg: no such file or directory" )
56
+ os .Unsetenv ("GNUPGHOME" )
57
+ }
58
+
59
+ func (s * LocalPGPTest ) TestBuildRingfileName () {
60
+ cases := []struct {
61
+ home string
62
+ gnupghome string
63
+ expected string
64
+ }{
65
+ {"/foo/" , "" , "/foo/.gnupg/pubring.gpg" },
66
+ {"/foo" , "" , "/foo/.gnupg/pubring.gpg" },
67
+ {"foo" , "" , "foo/.gnupg/pubring.gpg" },
68
+ {"foo" , "/things" , "/things/pubring.gpg" },
69
+ {"foo" , "/things/" , "/things/pubring.gpg" },
70
+ {"foo" , "things/" , "things/pubring.gpg" },
71
+ {"" , "/things/" , "/things/pubring.gpg" },
72
+ {"" , "" , ".gnupg/pubring.gpg" },
73
+ }
74
+
75
+ for _ , c := range cases {
76
+ os .Setenv ("HOME" , c .home )
77
+ os .Setenv ("GNUPGHOME" , c .gnupghome )
78
+ local := LocalPGPService {}
79
+ local .buildRingfileName ()
80
+ s .Equal (c .expected , local .ringfile )
81
+ }
82
+ }
83
+
51
84
func TestLocalPGPTest (t * testing.T ) {
52
85
suite .Run (t , new (LocalPGPTest ))
53
86
}
0 commit comments