github.com/cloudwego/hertz@v0.9.3/pkg/protocol/uri_unix_test.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  /*
     5   * Copyright 2023 CloudWeGo Authors
     6   *
     7   * Licensed under the Apache License, Version 2.0 (the "License");
     8   * you may not use this file except in compliance with the License.
     9   * You may obtain a copy of the License at
    10   *
    11   *  http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   */
    19  
    20  package protocol
    21  
    22  import (
    23  	"testing"
    24  
    25  	"github.com/cloudwego/hertz/pkg/common/test/assert"
    26  )
    27  
    28  func TestGetScheme(t *testing.T) {
    29  	scheme, path := getScheme([]byte("https://foo.com"))
    30  	assert.DeepEqual(t, "https", string(scheme))
    31  	assert.DeepEqual(t, "//foo.com", string(path))
    32  
    33  	scheme, path = getScheme([]byte(":"))
    34  	assert.DeepEqual(t, "", string(scheme))
    35  	assert.DeepEqual(t, "", string(path))
    36  
    37  	scheme, path = getScheme([]byte("ws://127.0.0.1"))
    38  	assert.DeepEqual(t, "ws", string(scheme))
    39  	assert.DeepEqual(t, "//127.0.0.1", string(path))
    40  
    41  	scheme, path = getScheme([]byte("/hertz/demo"))
    42  	assert.DeepEqual(t, "", string(scheme))
    43  	assert.DeepEqual(t, "/hertz/demo", string(path))
    44  }