Skip to content

Commit 83d38ea

Browse files
authored
Merge pull request docker#289 from crazy-max/build-constraint
chore: use go build constraint
2 parents c740b99 + 72391b3 commit 83d38ea

File tree

15 files changed

+112
-44
lines changed

15 files changed

+112
-44
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,19 @@ jobs:
5959
go-version: ${{ env.GO_VERSION }}
6060
cache: true
6161
-
62-
name: Install deps
62+
name: Install deps (ubuntu)
6363
if: startsWith(matrix.os, 'ubuntu-')
6464
run: |
6565
sudo apt-get update
6666
sudo apt-get install -y dbus-x11 gnome-keyring libsecret-1-dev pass
67+
-
68+
name: Install deps (macOS)
69+
if: startsWith(matrix.os, 'macOS-')
70+
run: |
71+
brew install pass
6772
-
6873
name: GPG conf
69-
if: startsWith(matrix.os, 'ubuntu-')
74+
if: ${{ !startsWith(matrix.os, 'windows-') }}
7075
uses: actions/github-script@v6
7176
id: gpg
7277
with:
@@ -83,18 +88,21 @@ jobs:
8388
core.setOutput('passphrase', fs.readFileSync('.github/workflows/fixtures/7D851EB72D73BDA0.pass', {encoding: 'utf8'}));
8489
-
8590
name: Import GPG key
86-
if: startsWith(matrix.os, 'ubuntu-')
91+
if: ${{ !startsWith(matrix.os, 'windows-') }}
8792
uses: crazy-max/ghaction-import-gpg@v5
8893
with:
8994
gpg_private_key: ${{ steps.gpg.outputs.key }}
9095
passphrase: ${{ steps.gpg.outputs.passphrase }}
96+
trust_level: 5
97+
-
98+
name: Init pass
99+
if: ${{ !startsWith(matrix.os, 'windows-') }}
100+
run: |
101+
pass init 7D851EB72D73BDA0
102+
shell: bash
91103
-
92104
name: Test
93105
run: |
94-
if [[ "${{ matrix.os }}" = ubuntu-* ]]; then
95-
echo -e "trust\n5\ny" | gpg --batch --no-tty --command-fd 0 --edit-key 7D851EB72D73BDA0
96-
pass init 7D851EB72D73BDA0
97-
fi
98106
make test COVERAGEDIR=${{ env.DESTDIR }}
99107
shell: bash
100108
-

osxkeychain/cmd/main_darwin.go renamed to osxkeychain/cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin && cgo
2+
13
package main
24

35
import (

osxkeychain/osxkeychain_darwin.c renamed to osxkeychain/osxkeychain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "osxkeychain_darwin.h"
1+
#include "osxkeychain.h"
22
#include <CoreFoundation/CoreFoundation.h>
33
#include <Foundation/NSValue.h>
44
#include <stdio.h>

osxkeychain/osxkeychain_darwin.go renamed to osxkeychain/osxkeychain.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
//go:build darwin && cgo
2+
13
package osxkeychain
24

35
/*
46
#cgo CFLAGS: -x objective-c
57
#cgo LDFLAGS: -framework Security -framework Foundation
68
7-
#include "osxkeychain_darwin.h"
9+
#include "osxkeychain.h"
810
#include <stdlib.h>
911
*/
1012
import "C"
File renamed without changes.

osxkeychain/osxkeychain_darwin_test.go renamed to osxkeychain/osxkeychain_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin && cgo
2+
13
package osxkeychain
24

35
import (

pass/pass_test.go

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !windows
2+
13
package pass
24

35
import (
@@ -8,75 +10,115 @@ import (
810
)
911

1012
func TestPassHelper(t *testing.T) {
11-
helper := Pass{}
12-
1313
creds := &credentials.Credentials{
1414
ServerURL: "https://foobar.docker.io:2376/v1",
1515
Username: "nothing",
1616
Secret: "isthebestmeshuggahalbum",
1717
}
1818

19-
_ = helper.CheckInitialized()
19+
helper := Pass{}
20+
if err := helper.checkInitialized(); err != nil {
21+
t.Error(err)
22+
}
23+
24+
if err := helper.Add(creds); err != nil {
25+
t.Error(err)
26+
}
27+
28+
u, s, err := helper.Get(creds.ServerURL)
29+
if err != nil {
30+
t.Error(err)
31+
}
32+
if u != creds.Username {
33+
t.Errorf("invalid username %s", u)
34+
}
35+
if s != creds.Secret {
36+
t.Errorf("invalid secret: %s", s)
37+
}
38+
39+
if err := helper.Delete(creds.ServerURL); err != nil {
40+
t.Error(err)
41+
}
42+
if _, _, err := helper.Get(creds.ServerURL); !credentials.IsErrCredentialsNotFound(err) {
43+
t.Errorf("expected credentials not found, actual: %v", err)
44+
}
45+
}
46+
47+
func TestPassHelperCheckInit(t *testing.T) {
48+
helper := Pass{}
49+
if v := helper.CheckInitialized(); !v {
50+
t.Errorf("expected true, actual: %v", v)
51+
}
52+
}
53+
54+
func TestPassHelperList(t *testing.T) {
55+
creds := []*credentials.Credentials{
56+
{
57+
ServerURL: "https://foobar.docker.io:2376/v1",
58+
Username: "foo",
59+
Secret: "isthebestmeshuggahalbum",
60+
},
61+
{
62+
ServerURL: "https://foobar.docker.io:2375/v1",
63+
Username: "bar",
64+
Secret: "isthebestmeshuggahalbum",
65+
},
66+
}
2067

21-
helper.Add(creds)
68+
helper := Pass{}
69+
if err := helper.checkInitialized(); err != nil {
70+
t.Error(err)
71+
}
2272

23-
creds.ServerURL = "https://foobar.docker.io:9999/v2"
24-
helper.Add(creds)
73+
for _, cred := range creds {
74+
if err := helper.Add(cred); err != nil {
75+
t.Error(err)
76+
}
77+
}
2578

2679
credsList, err := helper.List()
2780
if err != nil {
28-
t.Fatal(err)
81+
t.Error(err)
2982
}
30-
3183
for server, username := range credsList {
32-
if !(strings.Contains(server, "2376") ||
33-
strings.Contains(server, "9999")) {
34-
t.Fatalf("invalid url: %s", creds.ServerURL)
84+
if !(strings.HasSuffix(server, "2376/v1") || strings.HasSuffix(server, "2375/v1")) {
85+
t.Errorf("invalid url: %s", server)
3586
}
36-
37-
if username != "nothing" {
38-
t.Fatalf("invalid username: %v", username)
87+
if !(username == "foo" || username == "bar") {
88+
t.Errorf("invalid username: %v", username)
3989
}
4090

4191
u, s, err := helper.Get(server)
4292
if err != nil {
43-
t.Fatal(err)
93+
t.Error(err)
4494
}
45-
4695
if u != username {
47-
t.Fatalf("invalid username %s", u)
96+
t.Errorf("invalid username %s", u)
4897
}
49-
5098
if s != "isthebestmeshuggahalbum" {
51-
t.Fatalf("invalid secret: %s", s)
99+
t.Errorf("invalid secret: %s", s)
52100
}
53101

54-
err = helper.Delete(server)
55-
if err != nil {
56-
t.Fatal(err)
102+
if err := helper.Delete(server); err != nil {
103+
t.Error(err)
57104
}
58-
59-
_, _, err = helper.Get(server)
60-
if !credentials.IsErrCredentialsNotFound(err) {
61-
t.Fatalf("expected credentials not found, actual: %v", err)
105+
if _, _, err := helper.Get(server); !credentials.IsErrCredentialsNotFound(err) {
106+
t.Errorf("expected credentials not found, actual: %v", err)
62107
}
63108
}
64109

65110
credsList, err = helper.List()
66111
if err != nil {
67-
t.Fatal(err)
112+
t.Error(err)
68113
}
69-
70114
if len(credsList) != 0 {
71-
t.Fatal("didn't delete all creds?")
115+
t.Error("didn't delete all creds?")
72116
}
73117
}
74118

75119
func TestMissingCred(t *testing.T) {
76120
helper := Pass{}
77-
78-
_, _, err := helper.Get("garbage")
79-
if !credentials.IsErrCredentialsNotFound(err) {
80-
t.Fatalf("expected credentials not found, actual: %v", err)
121+
if _, _, err := helper.Get("garbage"); !credentials.IsErrCredentialsNotFound(err) {
122+
t.Errorf("expected credentials not found, actual: %v", err)
81123
}
82124
}

secretservice/cmd/main_linux.go renamed to secretservice/cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build linux && cgo
2+
13
package main
24

35
import (

secretservice/secretservice_linux.c renamed to secretservice/secretservice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <string.h>
22
#include <stdlib.h>
3-
#include "secretservice_linux.h"
3+
#include "secretservice.h"
44

55
const SecretSchema *docker_get_schema(void)
66
{

secretservice/secretservice_linux.go renamed to secretservice/secretservice.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//go:build linux && cgo
2+
13
package secretservice
24

35
/*
46
#cgo pkg-config: libsecret-1
57
6-
#include "secretservice_linux.h"
8+
#include "secretservice.h"
79
#include <stdlib.h>
810
*/
911
import "C"

0 commit comments

Comments
 (0)