示例#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 TestNewUpdateServiceSnapshot(t *testing.T) {
	preTest()

	cases := []struct {
		name     string
		expected bool
	}{
		{"mname0", true},
		{"invalidname", false},
	}

	for _, c := range cases {
		info := snapshot.SnapshotInputInfo{Name: c.name}
		_, err := snapshot.NewUpdateServiceSnapshot(info)
		assert.Equal(t, c.expected, err == nil, "Fail to create new snapshot")
	}
}