github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/config/compress/compress_test.go (about)

     1  // Copyright (c) 2015-2021 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package compress
    19  
    20  import (
    21  	"reflect"
    22  	"testing"
    23  )
    24  
    25  func TestParseCompressIncludes(t *testing.T) {
    26  	testCases := []struct {
    27  		str              string
    28  		expectedPatterns []string
    29  		success          bool
    30  	}{
    31  		// invalid input
    32  		{",,,", []string{}, false},
    33  		{"", []string{}, false},
    34  		{",", []string{}, false},
    35  		{"/", []string{}, false},
    36  		{"text/*,/", []string{}, false},
    37  
    38  		// valid input
    39  		{".txt,.log", []string{".txt", ".log"}, true},
    40  		{"text/*,application/json", []string{"text/*", "application/json"}, true},
    41  	}
    42  
    43  	for _, testCase := range testCases {
    44  		testCase := testCase
    45  		t.Run(testCase.str, func(t *testing.T) {
    46  			gotPatterns, err := parseCompressIncludes(testCase.str)
    47  			if !testCase.success && err == nil {
    48  				t.Error("expected failure but success instead")
    49  			}
    50  			if testCase.success && err != nil {
    51  				t.Errorf("expected success but failed instead %s", err)
    52  			}
    53  			if testCase.success && !reflect.DeepEqual(testCase.expectedPatterns, gotPatterns) {
    54  				t.Errorf("expected patterns %s but got %s", testCase.expectedPatterns, gotPatterns)
    55  			}
    56  		})
    57  	}
    58  }