github.com/quay/claircore@v1.5.28/oracle/updater_test.go (about) 1 package oracle 2 3 import ( 4 "context" 5 "net/http" 6 "net/http/httptest" 7 "testing" 8 9 "github.com/quay/zlog" 10 11 "github.com/quay/claircore/libvuln/driver" 12 ) 13 14 func TestFetch(t *testing.T) { 15 ctx := zlog.Test(context.Background(), t) 16 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 17 http.ServeFile(w, r, "testdata/com.oracle.elsa-2018.xml") 18 })) 19 u, err := NewUpdater(-1, WithURL(srv.URL, "")) 20 if err != nil { 21 t.Fatal(err) 22 } 23 if err := u.Configure(ctx, func(_ any) error { return nil }, srv.Client()); err != nil { 24 t.Fatal(err) 25 } 26 rd, hint, err := u.Fetch(ctx, "") 27 if err != nil { 28 t.Error(err) 29 } 30 t.Logf("got hint %q", hint) 31 if rd != nil { 32 rd.Close() 33 } 34 35 _, fp, err := u.Fetch(ctx, driver.Fingerprint(hint)) 36 t.Logf("got hint %q", fp) 37 if got, want := err, driver.Unchanged; got != want { 38 t.Errorf("got: %v, want: %v", got, want) 39 } 40 }