github.com/minio/minio-go/v6@v6.0.57/api-put-object_test.go (about)

     1  /*
     2   * MinIO Go Library for Amazon S3 Compatible Cloud Storage
     3   * Copyright 2015-2017 MinIO, Inc.
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package minio
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestPutObjectOptionsValidate(t *testing.T) {
    24  	testCases := []struct {
    25  		name, value string
    26  		shouldPass  bool
    27  	}{
    28  		// Invalid cases.
    29  		{"X-Amz-Matdesc", "blah", false},
    30  		{"x-amz-meta-X-Amz-Iv", "blah", false},
    31  		{"x-amz-meta-X-Amz-Key", "blah", false},
    32  		{"x-amz-meta-X-Amz-Matdesc", "blah", false},
    33  		{"It has spaces", "v", false},
    34  		{"It,has@illegal=characters", "v", false},
    35  		{"X-Amz-Iv", "blah", false},
    36  		{"X-Amz-Key", "blah", false},
    37  		{"X-Amz-Key-prefixed-header", "blah", false},
    38  		{"Content-Type", "custom/content-type", false},
    39  		{"content-type", "custom/content-type", false},
    40  		{"Content-Encoding", "gzip", false},
    41  		{"Cache-Control", "blah", false},
    42  		{"Content-Disposition", "something", false},
    43  		{"Content-Language", "somelanguage", false},
    44  
    45  		// Valid metadata names.
    46  		{"my-custom-header", "blah", true},
    47  		{"custom-X-Amz-Key-middle", "blah", true},
    48  		{"my-custom-header-X-Amz-Key", "blah", true},
    49  		{"blah-X-Amz-Matdesc", "blah", true},
    50  		{"X-Amz-MatDesc-suffix", "blah", true},
    51  		{"It-Is-Fine", "v", true},
    52  		{"Numbers-098987987-Should-Work", "v", true},
    53  		{"Crazy-!#$%&'*+-.^_`|~-Should-193832-Be-Fine", "v", true},
    54  	}
    55  	for i, testCase := range testCases {
    56  		err := PutObjectOptions{UserMetadata: map[string]string{
    57  			testCase.name: testCase.value,
    58  		}}.validate()
    59  		if testCase.shouldPass && err != nil {
    60  			t.Errorf("Test %d - output did not match with reference results, %s", i+1, err)
    61  		}
    62  	}
    63  }