github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/apim/APIMUtility_test.go (about)

     1  //go:build unit
     2  // +build unit
     3  
     4  package apim
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestOdataQueryInitExisting(t *testing.T) {
    13  	t.Run("MakeOdataQuery- Success Test", func(t *testing.T) {
    14  		odataFilterInputs := OdataParameters{Filter: "isCopy eq false", Search: "",
    15  			Top: 4, Skip: 1, Orderby: "name",
    16  			Select: "", Expand: ""}
    17  		odataFilters, err := OdataUtils.MakeOdataQuery(&odataFilterInputs)
    18  		assert.NoError(t, err)
    19  		assert.Equal(t, "?filter=isCopy+eq+false&$orderby=name&$skip=1&$top=4", odataFilters)
    20  	})
    21  
    22  	t.Run("MakeOdataQuery- empty odata filters Test", func(t *testing.T) {
    23  		odataFilterInputs := OdataParameters{Filter: "", Search: "",
    24  			Top: 0, Skip: 0, Orderby: "",
    25  			Select: "", Expand: ""}
    26  		odataFilters, err := OdataUtils.MakeOdataQuery(&odataFilterInputs)
    27  		assert.NoError(t, err)
    28  		assert.Equal(t, "", odataFilters)
    29  	})
    30  }