예제 #1
0
func TestRoundTrip(t *testing.T) {
	assert := assert.New(t)
	dc := docker_registry.NewDummyClient()

	host := "docker.repo.io"
	base := "ot/wackadoo"

	nc := NewNameCache(host, dc, inMemoryDB("roundtrip"))

	sv := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", "1.2.3")

	in := base + ":version-1.2.3"
	digest := "sha256:012345678901234567890123456789AB012345678901234567890123456789AB"
	err := nc.Insert(sv, in, digest, []sous.Quality{})
	assert.NoError(err)

	cn, err := nc.GetCanonicalName(in)
	if assert.NoError(err) {
		assert.Equal(in, cn)
	}
	nin, _, err := nc.getImageName(sv)
	if assert.NoError(err) {
		assert.Equal(in, nin)
	}

	newSV := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", "1.2.42")

	cn = base + "@" + digest
	dc.FeedMetadata(docker_registry.Metadata{
		Registry:      host,
		Labels:        Labels(newSV),
		Etag:          digest,
		CanonicalName: cn,
		AllNames:      []string{cn, in},
	})
	sv, err = nc.GetSourceID(NewBuildArtifact(in, nil))
	if assert.Nil(err) {
		assert.Equal(newSV, sv)
	}

	ncn, err := nc.GetCanonicalName(host + "/" + in)
	if assert.Nil(err) {
		assert.Equal(host+"/"+cn, ncn)
	}
}
예제 #2
0
func TestRegistries(t *testing.T) {
	assert := assert.New(t)

	rs := NewRegistries()
	r := &registry{}
	assert.NoError(rs.AddRegistry("x", r))
	assert.Equal(rs.GetRegistry("x"), r)
	assert.NoError(rs.DeleteRegistry("x"))
	assert.Nil(rs.GetRegistry("x"))
}
예제 #3
0
func TestReharvest(t *testing.T) {
	assert := assert.New(t)

	dc := docker_registry.NewDummyClient()
	_, err := dc.GetImageMetadata("", "")
	assert.Error(err) //because channel starved

	host := "docker.repo.io"
	base := "ot/wackadoo"

	nc := NewNameCache(host, dc, inMemoryDB("reharvest"))

	vstr := "1.2.3"
	sv := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", vstr)
	in := base + ":version-" + vstr
	digest := "sha256:012345678901234567890123456789AB012345678901234567890123456789AB"
	cn := base + "@" + digest

	dc.FeedMetadata(docker_registry.Metadata{
		Registry:      host,
		Labels:        Labels(sv),
		Etag:          digest,
		CanonicalName: cn,
		AllNames:      []string{cn, in},
	})
	gotSV, err := nc.GetSourceID(NewBuildArtifact(host+"/"+in, nil)) // XXX Really prefix with host?
	if assert.Nil(err) {
		assert.Equal(gotSV, sv)
	}
	nc.dump(os.Stderr)

	nc.DB.Exec("update _database_metadata_ set value='' where name='fingerprint'")

	dc.FeedTags([]string{"version" + vstr})
	dc.FeedMetadata(docker_registry.Metadata{
		Registry:      host,
		Labels:        Labels(sv),
		Etag:          digest,
		CanonicalName: cn,
		AllNames:      []string{cn, in},
	})
	nc.dump(os.Stderr)
	Log.Debug.SetOutput(os.Stderr)
	Log.Vomit.SetOutput(os.Stderr)
	err = nc.GroomDatabase()
	assert.NoError(err)
	nc.dump(os.Stderr)

	_, err = dc.GetImageMetadata("", "")
	assert.Error(err) //because channel starved
	list, _ := dc.AllTags("")
	assert.Len(list, 0) //because channel starved
}
예제 #4
0
func TestGetLabels(t *testing.T) {
	registerLabelledContainers()
	assert := assert.New(t)
	cl := docker_registry.NewClient()
	cl.BecomeFoolishlyTrusting()

	labels, err := cl.LabelsForImageName(imageName)

	assert.Nil(err)
	assert.Contains(labels, docker.DockerRepoLabel)
	ResetSingularity()
}
예제 #5
0
func TestHarvesting(t *testing.T) {
	assert := assert.New(t)
	dc := docker_registry.NewDummyClient()

	host := "docker.repo.io"
	base := "ot/wackadoo"
	nc := NewNameCache(host, dc, inMemoryDB("harvesting"))

	v := "1.2.3"
	sv := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", v)

	v2 := "2.3.4"
	sisterSV := sous.MustNewSourceID("https://github.com/opentable/wackadoo", "nested/there", v2)

	tag := "version-1.2.3"
	digest := "sha256:012345678901234567890123456789AB012345678901234567890123456789AB"
	cn := base + "@" + digest
	in := base + ":" + tag

	dc.FeedMetadata(docker_registry.Metadata{
		Registry:      host,
		Labels:        Labels(sv),
		Etag:          digest,
		CanonicalName: cn,
		AllNames:      []string{cn, in},
	})

	// a la a SetCollector getting the SV
	_, err := nc.GetSourceID(NewBuildArtifact(in, nil))
	if err != nil {
		fmt.Printf("%+v", err)
	}
	assert.Nil(err)

	tag = "version-2.3.4"
	dc.FeedTags([]string{tag})
	digest = "sha256:abcdefabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeffffffff"
	cn = base + "@" + digest
	in = base + ":" + tag
	dc.FeedMetadata(docker_registry.Metadata{
		Registry:      host,
		Labels:        Labels(sisterSV),
		Etag:          digest,
		CanonicalName: cn,
		AllNames:      []string{cn, in},
	})

	nin, err := nc.GetArtifact(sisterSV)
	if assert.NoError(err) {
		assert.Equal(host+"/"+cn, nin.Name)
	}
}
예제 #6
0
파일: require.go 프로젝트: opentable/sous
// Nil asserts that the specified object is nil.
//
//    assert.Nil(t, err, "err should be nothing")
//
// Returns whether the assertion was successful (true) or not (false).
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
	if !assert.Nil(t, object, msgAndArgs...) {
		t.FailNow()
	}
}