mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
0640a14b4f
Using gomvpkg -from github.com/docker/docker/api/client -to github.com/docker/docker/cli/command -vcs_mv_cmd 'git mv {{.Src}} {{.Dst}}' Signed-off-by: Daniel Nephin <dnephin@docker.com>
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
registrytypes "github.com/docker/docker/api/types/registry"
|
|
"github.com/docker/docker/registry"
|
|
)
|
|
|
|
func unsetENV() {
|
|
os.Unsetenv("DOCKER_CONTENT_TRUST")
|
|
os.Unsetenv("DOCKER_CONTENT_TRUST_SERVER")
|
|
}
|
|
|
|
func TestENVTrustServer(t *testing.T) {
|
|
defer unsetENV()
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
|
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.com:5000"); err != nil {
|
|
t.Fatal("Failed to set ENV variable")
|
|
}
|
|
output, err := trustServer(indexInfo)
|
|
expectedStr := "https://notary-test.com:5000"
|
|
if err != nil || output != expectedStr {
|
|
t.Fatalf("Expected server to be %s, got %s", expectedStr, output)
|
|
}
|
|
}
|
|
|
|
func TestHTTPENVTrustServer(t *testing.T) {
|
|
defer unsetENV()
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
|
if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.com:5000"); err != nil {
|
|
t.Fatal("Failed to set ENV variable")
|
|
}
|
|
_, err := trustServer(indexInfo)
|
|
if err == nil {
|
|
t.Fatal("Expected error with invalid scheme")
|
|
}
|
|
}
|
|
|
|
func TestOfficialTrustServer(t *testing.T) {
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: true}
|
|
output, err := trustServer(indexInfo)
|
|
if err != nil || output != registry.NotaryServer {
|
|
t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output)
|
|
}
|
|
}
|
|
|
|
func TestNonOfficialTrustServer(t *testing.T) {
|
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: false}
|
|
output, err := trustServer(indexInfo)
|
|
expectedStr := "https://" + indexInfo.Name
|
|
if err != nil || output != expectedStr {
|
|
t.Fatalf("Expected server to be %s, got %s", expectedStr, output)
|
|
}
|
|
}
|