client/driver: gaurd authHelper test from running on windows
This commit is contained in:
parent
91603a377e
commit
c4d07a2200
41
client/driver/docker_linux_test.go
Normal file
41
client/driver/docker_linux_test.go
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package driver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDockerDriver_authFromHelper(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir("", "test-docker-driver_authfromhelper")
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
helperPayload := "{\"Username\":\"hashi\",\"Secret\":\"nomad\"}"
|
||||||
|
helperContent := []byte(fmt.Sprintf("#!/bin/sh\ncat > %s/helper-$1.out;echo '%s'", dir, helperPayload))
|
||||||
|
|
||||||
|
helperFile := filepath.Join(dir, "docker-credential-testnomad")
|
||||||
|
err = ioutil.WriteFile(helperFile, helperContent, 0777)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
path := os.Getenv("PATH")
|
||||||
|
os.Setenv("PATH", fmt.Sprintf("%s:%s", path, dir))
|
||||||
|
defer os.Setenv("PATH", path)
|
||||||
|
|
||||||
|
helper := authFromHelper("testnomad")
|
||||||
|
creds, err := helper("registry.local:5000/repo/image")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, creds)
|
||||||
|
require.Equal(t, "hashi", creds.Username)
|
||||||
|
require.Equal(t, "nomad", creds.Password)
|
||||||
|
|
||||||
|
if _, err := os.Stat(filepath.Join(dir, "helper-get.out")); os.IsNotExist(err) {
|
||||||
|
t.Fatalf("Expected helper-get.out to exist")
|
||||||
|
}
|
||||||
|
content, err := ioutil.ReadFile(filepath.Join(dir, "helper-get.out"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []byte("https://registry.local:5000"), content)
|
||||||
|
}
|
|
@ -2458,33 +2458,3 @@ func TestDockerDriver_AdvertiseIPv6Address(t *testing.T) {
|
||||||
t.Fatalf("Got GlobalIPv6address %s want GlobalIPv6address with prefix %s", expectedPrefix, container.NetworkSettings.GlobalIPv6Address)
|
t.Fatalf("Got GlobalIPv6address %s want GlobalIPv6address with prefix %s", expectedPrefix, container.NetworkSettings.GlobalIPv6Address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDockerDriver_authFromHelper(t *testing.T) {
|
|
||||||
dir, err := ioutil.TempDir("", "test-docker-driver_authfromhelper")
|
|
||||||
require.NoError(t, err)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
helperPayload := "{\"Username\":\"hashi\",\"Secret\":\"nomad\"}"
|
|
||||||
helperContent := []byte(fmt.Sprintf("#!/bin/sh\ncat > %s/helper-$1.out;echo '%s'", dir, helperPayload))
|
|
||||||
|
|
||||||
helperFile := filepath.Join(dir, "docker-credential-testnomad")
|
|
||||||
err = ioutil.WriteFile(helperFile, helperContent, 0777)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
path := os.Getenv("PATH")
|
|
||||||
os.Setenv("PATH", fmt.Sprintf("%s:%s", path, dir))
|
|
||||||
defer os.Setenv("PATH", path)
|
|
||||||
|
|
||||||
helper := authFromHelper("testnomad")
|
|
||||||
creds, err := helper("registry.local:5000/repo/image")
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NotNil(t, creds)
|
|
||||||
require.Equal(t, "hashi", creds.Username)
|
|
||||||
require.Equal(t, "nomad", creds.Password)
|
|
||||||
|
|
||||||
if _, err := os.Stat(filepath.Join(dir, "helper-get.out")); os.IsNotExist(err) {
|
|
||||||
t.Fatalf("Expected helper-get.out to exist")
|
|
||||||
}
|
|
||||||
content, err := ioutil.ReadFile(filepath.Join(dir, "helper-get.out"))
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, []byte("https://registry.local:5000"), content)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue