storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/config/compress/compress_test.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2019 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package compress
    18  
    19  import (
    20  	"reflect"
    21  	"testing"
    22  )
    23  
    24  func TestParseCompressIncludes(t *testing.T) {
    25  	testCases := []struct {
    26  		str              string
    27  		expectedPatterns []string
    28  		success          bool
    29  	}{
    30  		// invalid input
    31  		{",,,", []string{}, false},
    32  		{"", []string{}, false},
    33  		{",", []string{}, false},
    34  		{"/", []string{}, false},
    35  		{"text/*,/", []string{}, false},
    36  
    37  		// valid input
    38  		{".txt,.log", []string{".txt", ".log"}, true},
    39  		{"text/*,application/json", []string{"text/*", "application/json"}, true},
    40  	}
    41  
    42  	for _, testCase := range testCases {
    43  		testCase := testCase
    44  		t.Run(testCase.str, func(t *testing.T) {
    45  			gotPatterns, err := parseCompressIncludes(testCase.str)
    46  			if !testCase.success && err == nil {
    47  				t.Error("expected failure but success instead")
    48  			}
    49  			if testCase.success && err != nil {
    50  				t.Errorf("expected success but failed instead %s", err)
    51  			}
    52  			if testCase.success && !reflect.DeepEqual(testCase.expectedPatterns, gotPatterns) {
    53  				t.Errorf("expected patterns %s but got %s", testCase.expectedPatterns, gotPatterns)
    54  			}
    55  		})
    56  	}
    57  }