zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/pkg/cli/client/gql_queries_test.go (about)

     1  //go:build search
     2  // +build search
     3  
     4  package client_test
     5  
     6  import (
     7  	"io"
     8  	"testing"
     9  
    10  	. "github.com/smartystreets/goconvey/convey"
    11  
    12  	"zotregistry.io/zot/pkg/api"
    13  	"zotregistry.io/zot/pkg/api/config"
    14  	"zotregistry.io/zot/pkg/cli/client"
    15  	extconf "zotregistry.io/zot/pkg/extensions/config"
    16  	test "zotregistry.io/zot/pkg/test/common"
    17  )
    18  
    19  func TestGQLQueries(t *testing.T) {
    20  	port := test.GetFreePort()
    21  	baseURL := test.GetBaseURL(port)
    22  	conf := config.New()
    23  	conf.HTTP.Port = port
    24  	dir := t.TempDir()
    25  	conf.Storage.RootDirectory = dir
    26  	defaultVal := true
    27  	conf.Extensions = &extconf.ExtensionConfig{
    28  		Search: &extconf.SearchConfig{
    29  			BaseConfig: extconf.BaseConfig{Enable: &defaultVal},
    30  		},
    31  	}
    32  
    33  	ctlr := api.NewController(conf)
    34  
    35  	cm := test.NewControllerManager(ctlr)
    36  	cm.StartAndWait(conf.HTTP.Port)
    37  
    38  	defer cm.StopServer()
    39  
    40  	searchConfig := client.SearchConfig{
    41  		ServURL:      baseURL,
    42  		User:         "",
    43  		VerifyTLS:    false,
    44  		Debug:        false,
    45  		ResultWriter: io.Discard,
    46  	}
    47  
    48  	Convey("Make sure the current CLI used the right queries in case they change", t, func() {
    49  		Convey("ImageList", func() {
    50  			err := client.CheckExtEndPointQuery(searchConfig, client.ImageListQuery())
    51  			So(err, ShouldBeNil)
    52  		})
    53  
    54  		Convey("ImageListForDigest", func() {
    55  			err := client.CheckExtEndPointQuery(searchConfig, client.ImageListForDigestQuery())
    56  			So(err, ShouldBeNil)
    57  		})
    58  
    59  		Convey("BaseImageList", func() {
    60  			err := client.CheckExtEndPointQuery(searchConfig, client.BaseImageListQuery())
    61  			So(err, ShouldBeNil)
    62  		})
    63  
    64  		Convey("DerivedImageList", func() {
    65  			err := client.CheckExtEndPointQuery(searchConfig, client.DerivedImageListQuery())
    66  			So(err, ShouldBeNil)
    67  		})
    68  
    69  		Convey("CVEListForImage", func() {
    70  			err := client.CheckExtEndPointQuery(searchConfig, client.CVEListForImageQuery())
    71  			So(err, ShouldBeNil)
    72  		})
    73  
    74  		Convey("ImageListForCVE", func() {
    75  			err := client.CheckExtEndPointQuery(searchConfig, client.ImageListForCVEQuery())
    76  			So(err, ShouldBeNil)
    77  		})
    78  
    79  		Convey("ImageListWithCVEFixed", func() {
    80  			err := client.CheckExtEndPointQuery(searchConfig, client.ImageListWithCVEFixedQuery())
    81  			So(err, ShouldBeNil)
    82  		})
    83  
    84  		Convey("Referrers", func() {
    85  			err := client.CheckExtEndPointQuery(searchConfig, client.ReferrersQuery())
    86  			So(err, ShouldBeNil)
    87  		})
    88  
    89  		Convey("GlobalSearch", func() {
    90  			err := client.CheckExtEndPointQuery(searchConfig, client.GlobalSearchQuery())
    91  			So(err, ShouldBeNil)
    92  		})
    93  	})
    94  }