github.com/quay/claircore@v1.5.28/alpine/fetcher_test.go (about)

     1  package alpine
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"net/http/httptest"
     7  	"testing"
     8  
     9  	"github.com/google/go-cmp/cmp"
    10  	"github.com/quay/zlog"
    11  )
    12  
    13  func serveSecDB(t *testing.T) (string, *http.Client) {
    14  	srv := httptest.NewServer(http.FileServer(http.Dir("testdata/fetch")))
    15  	t.Cleanup(srv.Close)
    16  	return srv.URL, srv.Client()
    17  }
    18  
    19  func TestFactory(t *testing.T) {
    20  	ctx := zlog.Test(context.Background(), t)
    21  	root, c := serveSecDB(t)
    22  	fac := &Factory{}
    23  	err := fac.Configure(ctx, func(v interface{}) error {
    24  		cf := v.(*FactoryConfig)
    25  		cf.URL = root + "/"
    26  		return nil
    27  	}, c)
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	s, err := fac.UpdaterSet(ctx)
    32  	if err != nil {
    33  		t.Error(err)
    34  	}
    35  	us := s.Updaters()
    36  	if len(us) == 0 {
    37  		t.Errorf("expected more than 0 updaters")
    38  	}
    39  	got := make([]string, len(us))
    40  	for i, u := range us {
    41  		got[i] = u.Name()
    42  	}
    43  	want := []string{
    44  		"alpine-community-v3.10-updater",
    45  	}
    46  	if !cmp.Equal(got, want) {
    47  		t.Error(cmp.Diff(got, want))
    48  	}
    49  }