Exemple #1
0
// Put returns encoded id
func (t *ScanHookTask) Put(rID int64, url string) (int64, error) {
	if url == "" || rID == 0 {
		return 0, errors.New("'URL' and 'RegistID' should not be empty")
	}

	var reg ScanHookRegist
	reg, err := reg.FindByID(rID)
	if err != nil {
		return 0, err
	}

	//TODO: add to db and get task ID
	var encodedCallbackID string
	var info snapshot.SnapshotInputInfo
	info.Name = reg.ScanPluginName
	info.CallbackID = encodedCallbackID
	info.DataProto = reg.Proto
	info.DataURL = url
	// Do the real scan work
	s, err := snapshot.NewUpdateServiceSnapshot(info)
	if err != nil {
		return 0, err
	}

	err = s.Process()
	if err != nil {
		return 0, err
	}

	return 0, nil
}
func TestInfoGetName(t *testing.T) {
	cases := []struct {
		name           string
		expectedPlugin string
		expectedImage  string
	}{
		{"appv1", "appv1", ""},
		{"bycontainer/ospaf/scan", "bycontainer", "ospaf/scan"},
	}

	for _, c := range cases {
		info := snapshot.SnapshotInputInfo{Name: c.name}
		p, i := info.GetName()
		assert.Equal(t, c.expectedPlugin, p, "Fail to get plugin name")
		assert.Equal(t, c.expectedImage, i, "Fail to get image name")
	}
}