Skip to content

Commit

Permalink
vagrant: add a windows box for wincred dev/test
Browse files Browse the repository at this point in the history
  • Loading branch information
joemiller committed Jun 12, 2019
1 parent f97f7b3 commit 15841a1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 13 deletions.
18 changes: 12 additions & 6 deletions libsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package keyring

import (
"encoding/json"
"fmt"
"errors"

"github.com/godbus/dbus"
"github.com/gsterjov/go-libsecret"
Expand Down Expand Up @@ -54,6 +54,8 @@ func (e *secretsError) Error() string {
return e.message
}

var ErrCollectionNotFound = errors.New("The collection does not exist. Please add a key first")

func (k *secretsKeyring) openSecrets() error {
session, err := k.service.Open()
if err != nil {
Expand Down Expand Up @@ -85,17 +87,21 @@ func (k *secretsKeyring) openCollection() error {
}

if k.collection == nil {
return &secretsError{fmt.Sprintf(
"The collection %q does not exist. Please add a key first",
k.name,
)}
return ErrCollectionNotFound
// return &secretsError{fmt.Sprintf(
// "The collection %q does not exist. Please add a key first",
// k.name,
// )}
}

return nil
}

func (k *secretsKeyring) Get(key string) (Item, error) {
if err := k.openCollection(); err != nil {
if err == ErrCollectionNotFound {
return Item{}, ErrKeyNotFound
}
return Item{}, err
}

Expand All @@ -105,7 +111,7 @@ func (k *secretsKeyring) Get(key string) (Item, error) {
}

if len(items) == 0 {
return Item{}, err
return Item{}, ErrKeyNotFound
}

// use the first item whenever there are multiples
Expand Down
29 changes: 25 additions & 4 deletions libsecret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,30 @@ func TestLibSecretGetWhenNotEmpty(t *testing.T) {
}
}

// func TestLibSecretRemoveWhenEmpty(t *testing.T) {
// kr, _ := libSecretSetup(t)
func TestLibSecretRemoveWhenEmpty(t *testing.T) {
kr, _ := libSecretSetup(t)

err := kr.Remove("no-such-key")
if err == ErrCollectionNotFound {
t.Fatal("Expected keyring.ErrCollectionNotFound")
}
}

func TestLibSecretRemoveWhenNotEmpty(t *testing.T) {
kr, teardown := libSecretSetup(t)
defer teardown(t)

item := Item{Key: "llamas", Data: []byte("llamas are great")}

// }
if err := kr.Set(item); err != nil {
t.Fatal(err)
}

// func TestLibSecretRemoveWhenNotEmpty(t *testing.T) {}
if _, err := kr.Get("llamas"); err != nil {
t.Fatal(err)
}

if err := kr.Remove("llamas"); err != nil {
t.Fatal(err)
}
}
27 changes: 24 additions & 3 deletions vagrant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This directory contains Vagrant images for use in development and testing.
Using
-----

### Fedora (Gnome desktop)

**Pre-Reqs:**

1. Install vagrant
Expand Down Expand Up @@ -38,7 +40,26 @@ cd /src
go test -v ./...
```

TODO
----
### Windows 10

**Pre-Reqs:**

1. Install vagrant

**Launch**:

- [ ] A Windows Vagrant VM for testing wincred.go
```sh
cd vagrant/windows
vagrant up
```

`git` and `go` will be installed via the chocolately package manager.

A GUI will open up. Login and open cmd or powershell.

The root of the project will be mounted to `C:\src`

```sh
cd C:\src
go test -v .
```
24 changes: 24 additions & 0 deletions vagrant/windows/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Vagrant.configure("2") do |config|
# https://app.vagrantup.com/StefanScherer/boxes/windows_10
config.vm.box = "StefanScherer/windows_10"
config.vm.box_version = "2019.05.22"

config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = 2048
vb.cpus = 2
vb.customize ["modifyvm", :id, "--vram", "128"]
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
end

# install chocolately pkg manager
config.vm.provision "shell", privileged: true, inline: <<-SHELL
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
SHELL

config.vm.provision "shell", inline: "choco install -y git"
config.vm.provision "shell", inline: "choco install -y golang"

# mount the project into c:\src
config.vm.synced_folder "../..", "/src"
end

0 comments on commit 15841a1

Please sign in to comment.