Browse Source

linting: a few fixes

pull/1782/head
Zach Ramsay 7 years ago
parent
commit
47d3fa4741
4 changed files with 17 additions and 22 deletions
  1. +1
    -1
      Makefile
  2. +4
    -4
      embed_test.go
  3. +7
    -7
      keys/cryptostore/holder_test.go
  4. +5
    -10
      keys/storage/filestorage/main.go

+ 1
- 1
Makefile View File

@ -41,7 +41,6 @@ metalinter: ensure_tools
metalinter_test: ensure_tools
@gometalinter --install
gometalinter --vendor --deadline=600s --disable-all \
--enable=aligncheck \
--enable=deadcode \
--enable=gas \
--enable=goconst \
@ -49,6 +48,7 @@ metalinter_test: ensure_tools
--enable=gosimple \
--enable=ineffassign \
--enable=interfacer \
--enable=maligned \
--enable=megacheck \
--enable=misspell \
--enable=safesql \


+ 4
- 4
embed_test.go View File

@ -73,8 +73,8 @@ func TestEncodeDemo(t *testing.T) {
// Try to encode as binary
b, err := data.ToWire(tc.in)
if assert.Nil(err, "%d: %#v", i, tc.in) {
err := data.FromWire(b, tc.out)
if assert.Nil(err) {
err2 := data.FromWire(b, tc.out)
if assert.Nil(err2) {
assert.Equal(tc.expected, tc.out.String())
}
}
@ -82,8 +82,8 @@ func TestEncodeDemo(t *testing.T) {
// Try to encode it as json
j, err := data.ToJSON(tc.in)
if assert.Nil(err, "%d: %#v", i, tc.in) {
err := data.FromJSON(j, tc.out)
if assert.Nil(err) {
err2 := data.FromJSON(j, tc.out)
if assert.Nil(err2) {
assert.Equal(tc.expected, tc.out.String())
}
}


+ 7
- 7
keys/cryptostore/holder_test.go View File

@ -50,22 +50,22 @@ func TestKeyManagement(t *testing.T) {
assert.NotNil(err)
// list shows them in order
keys, err := cstore.List()
keyS, err := cstore.List()
require.Nil(err)
require.Equal(2, len(keys))
require.Equal(2, len(keyS))
// note these are in alphabetical order
assert.Equal(n2, keys[0].Name)
assert.Equal(n1, keys[1].Name)
assert.Equal(i2.PubKey, keys[0].PubKey)
assert.Equal(n2, keyS[0].Name)
assert.Equal(n1, keyS[1].Name)
assert.Equal(i2.PubKey, keyS[0].PubKey)
// deleting a key removes it
err = cstore.Delete("bad name", "foo")
require.NotNil(err)
err = cstore.Delete(n1, p1)
require.Nil(err)
keys, err = cstore.List()
keyS, err = cstore.List()
require.Nil(err)
assert.Equal(1, len(keys))
assert.Equal(1, len(keyS))
_, err = cstore.Get(n1)
assert.NotNil(err)


+ 5
- 10
keys/storage/filestorage/main.go View File

@ -89,11 +89,10 @@ func (s FileStore) Get(name string) (salt []byte, key []byte, info keys.Info, er
// Info for all keys located in this directory.
func (s FileStore) List() (keys.Infos, error) {
dir, err := os.Open(s.keyDir)
defer dir.Close()
if err != nil {
return nil, errors.Wrap(err, "List Keys")
}
defer dir.Close()
names, err := dir.Readdirnames(0)
if err != nil {
@ -141,11 +140,10 @@ func (s FileStore) nameToPaths(name string) (pub, priv string) {
func readInfo(path string) (info keys.Info, err error) {
f, err := os.Open(path)
defer f.Close()
if err != nil {
return info, errors.Wrap(err, "Reading data")
}
defer f.Close()
d, err := ioutil.ReadAll(f)
if err != nil {
@ -170,11 +168,10 @@ func readInfo(path string) (info keys.Info, err error) {
func read(path string) (salt, key []byte, name string, err error) {
f, err := os.Open(path)
defer f.Close()
if err != nil {
return nil, nil, "", errors.Wrap(err, "Reading data")
}
defer f.Close()
d, err := ioutil.ReadAll(f)
if err != nil {
@ -208,11 +205,10 @@ func read(path string) (salt, key []byte, name string, err error) {
func writeInfo(path string, info keys.Info) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, keyPerm)
defer f.Close()
if err != nil {
return errors.Wrap(err, "Writing data")
}
defer f.Close()
headers := map[string]string{"name": info.Name}
text := crypto.EncodeArmor(BlockType, headers, info.PubKey.Bytes())
@ -223,11 +219,10 @@ func writeInfo(path string, info keys.Info) error {
func write(path, name string, salt, key []byte) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, keyPerm)
defer f.Close()
if err != nil {
return errors.Wrap(err, "Writing data")
}
defer f.Close()
headers := map[string]string{
"name": name,


Loading…
Cancel
Save