github.com/GuanceCloud/cliutils@v1.1.21/point/category_test.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  package point
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestURL(t *testing.T) {
    15  	cases := []struct {
    16  		c      string
    17  		expect Category
    18  	}{
    19  		{c: "/v1/write/x", expect: UnknownCategory},
    20  		{c: "/v1/write/metric", expect: Metric},
    21  		{c: "/v1/write/logging", expect: Logging},
    22  		{c: "/v1/write/object", expect: Object},
    23  		{c: "/v1/write/metrics", expect: MetricDeprecated},
    24  		{c: "/v1/write/network", expect: Network},
    25  		{c: "/v1/write/rum", expect: RUM},
    26  		{c: "/v1/write/security", expect: Security},
    27  		{c: "/v1/write/profiling", expect: Profiling},
    28  		{c: "/v1/write/keyevent", expect: KeyEvent},
    29  		{c: "/v1/write/tracing", expect: Tracing},
    30  		{c: "/v1/write/dynamic_dw", expect: DynamicDWCategory},
    31  	}
    32  
    33  	for _, tc := range cases {
    34  		t.Run(tc.c, func(t *testing.T) {
    35  			assert.Equal(t, tc.expect.String(), CatURL(tc.c).String())
    36  		})
    37  	}
    38  }
    39  
    40  func TestAlias(t *testing.T) {
    41  	cases := []struct {
    42  		c      string
    43  		expect Category
    44  	}{
    45  		{c: "X", expect: UnknownCategory},
    46  		{c: "M", expect: Metric},
    47  		{c: "L", expect: Logging},
    48  		{c: "O", expect: Object},
    49  		{c: "N", expect: Network},
    50  		{c: "R", expect: RUM},
    51  		{c: "S", expect: Security},
    52  		{c: "P", expect: Profiling},
    53  		{c: "E", expect: KeyEvent},
    54  		{c: "T", expect: Tracing},
    55  		{c: "Dynamic_dw", expect: UnknownCategory},
    56  	}
    57  
    58  	for _, tc := range cases {
    59  		t.Run(tc.c, func(t *testing.T) {
    60  			assert.Equal(t, tc.expect, CatAlias(tc.c))
    61  		})
    62  	}
    63  }
    64  
    65  func TestString(t *testing.T) {
    66  	cases := []struct {
    67  		c      string
    68  		expect Category
    69  	}{
    70  		{c: "balabala", expect: UnknownCategory},
    71  		{c: "metric", expect: Metric},
    72  		{c: "metrics", expect: MetricDeprecated},
    73  		{c: "logging", expect: Logging},
    74  		{c: "object", expect: Object},
    75  		{c: "network", expect: Network},
    76  		{c: "rum", expect: RUM},
    77  		{c: "security", expect: Security},
    78  		{c: "profiling", expect: Profiling},
    79  		{c: "keyevent", expect: KeyEvent},
    80  		{c: "tracing", expect: Tracing},
    81  		{c: "dynamic_dw", expect: DynamicDWCategory},
    82  	}
    83  
    84  	for _, tc := range cases {
    85  		t.Run(tc.c, func(t *testing.T) {
    86  			assert.Equal(t, tc.expect, CatString(tc.c))
    87  		})
    88  	}
    89  }