github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/utils/specutils_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  )
     7  
     8  func TestAqlUnmarshalJSON(t *testing.T) {
     9  	tests := []struct {
    10  		name      string
    11  		itemsFind string
    12  		expected  string
    13  	}{
    14  		{"test1", "{\"items.find\":{}}", "{}"},
    15  		{"test2", "{\"items.find\": {}}", "{}"},
    16  		{"test3", "  {  \"items.find\"\n  :    {}  }  ", "{}  "},
    17  		{"test4", "  {  \"items.find\"\n  :    {  \"inside\"  :  \"something\"  }  }  ", "{  \"inside\"  :  \"something\"  }  "},
    18  	}
    19  	for _, test := range tests {
    20  		t.Run(test.name, func(t *testing.T) {
    21  			aql := &Aql{}
    22  			err := json.Unmarshal([]byte(test.itemsFind), aql)
    23  			if err != nil {
    24  				t.Error(err)
    25  			}
    26  			if aql.ItemsFind != test.expected {
    27  				t.Error("Test:", test.name, "Expected:", "'"+test.expected+"'", "got:", "'"+aql.ItemsFind+"'")
    28  			}
    29  		})
    30  	}
    31  }