storj.io/uplink@v1.13.0/object_test.go (about)

     1  // Copyright (C) 2020 Storj Labs, Inc.
     2  // See LICENSE for copying information.
     3  
     4  package uplink_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"storj.io/uplink"
    12  )
    13  
    14  func TestCustomMetadata_Verify_Valid(t *testing.T) {
    15  	metas := []uplink.CustomMetadata{
    16  		{"content-type": "application/json"},
    17  		{"hellö": "wörld"},
    18  		{"hellö": "世界"},
    19  		{"世界": "hellö"},
    20  	}
    21  	for _, meta := range metas {
    22  		require.NoError(t, meta.Verify(), meta)
    23  	}
    24  }
    25  
    26  func TestCustomMetadata_Verify_Invalid(t *testing.T) {
    27  	metas := []uplink.CustomMetadata{
    28  		{"": "application/json"},
    29  		{"A\x00B": "no zero byte"},
    30  		{"no zero byte": "A\x00B"},
    31  		{"\x00": "no zero byte"},
    32  		{"no zero byte": "\x00"},
    33  		{"A\xff\xff\xff\xff\xffB": "no invalid rune"},
    34  		{"no invalid rune": "A\xff\xff\xff\xff\xffB"},
    35  	}
    36  	for _, meta := range metas {
    37  		require.Error(t, meta.Verify(), meta)
    38  	}
    39  }