harness-drone/plugin/registry/file_test.go

40 lines
927 B
Go
Raw Normal View History

2019-02-19 23:56:41 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
package registry
import (
"os"
"testing"
"github.com/drone/drone/core"
"github.com/google/go-cmp/cmp"
)
func TestFileSource(t *testing.T) {
source := FileSource("./auths/testdata/config.json")
got, err := source.List(noContext, &core.RegistryArgs{})
if err != nil {
t.Error(err)
}
want := []*core.Registry{
{
Address: "https://index.docker.io/v1/",
Username: "octocat",
Password: "correct-horse-battery-staple",
},
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf(diff)
}
}
func TestFileSourceErr(t *testing.T) {
source := FileSource("./auths/testdata/x.json")
_, err := source.List(noContext, &core.RegistryArgs{})
if _, ok := err.(*os.PathError); !ok {
t.Errorf("Expect error when file does not exist")
}
}