// Regist regists a repository with a scan image // A namespace/repository could have multiple ScanPluginName, // but now we only support one. func (s *ScanHookRegist) Regist(p, n, r, name string) error { if p == "" || n == "" || r == "" || name == "" { return errors.New("'Proto', 'Namespace', 'Repository' and 'ScanPluginName' should not be empty") } info := snapshot.SnapshotInputInfo{DataProto: p, Name: name} if ok, err := snapshot.IsSnapshotSupported(info); !ok { return err } s.Proto, s.Namespace, s.Repository, s.ScanPluginName = p, n, r, name //TODO: add to db return nil }
func TestIsSnapshotSupported(t *testing.T) { preTest() cases := []struct { p string n string expected bool }{ {"mock", "mname0", true}, {"mock", "invalid", false}, {"invalid", "mname0", false}, } for _, c := range cases { info := snapshot.SnapshotInputInfo{DataProto: c.p, Name: c.n} ok, _ := snapshot.IsSnapshotSupported(info) assert.Equal(t, c.expected, ok, "Fail to get supported result") } }