go.uber.org/yarpc@v1.72.1/internal/servicename_test.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package internal 22 23 import ( 24 "testing" 25 26 "github.com/stretchr/testify/assert" 27 ) 28 29 func TestValidServiceNames(t *testing.T) { 30 tests := []string{ 31 "aa", 32 "superskipper", 33 "supper-skipper", 34 "supperskipper83", 35 "supper-skipper83", 36 "supper_skipper83", 37 "a77ab7g4-51cb-4808-a9ef-875568bde54a", // not valid UUID 38 "eviluuid26695g10-a384-48e7-8867-6d48b7fae80a", // not valid UUID 39 "a77gb7e4-51cb-4808-a9ef-875568bde54aeviluuid", // not valid UUID 40 } 41 for _, n := range tests { 42 assert.NoError(t, ValidateServiceName(n), "Expected %q to be a valid service name.", n) 43 } 44 } 45 46 func TestInvalidServiceNames(t *testing.T) { 47 tests := []string{ 48 "a", 49 "a77ab7e4-51cb-4808-a9ef-875568bde54a", 50 "urn:uuid:a77ab7e4-51cb-4808-a9ef-875568bde54a", 51 "26695a10-a384-48e7-8867-6d48b7fae80a", 52 "eviluuid26695a10-a384-48e7-8867-6d48b7fae80a", 53 "a77ab7e4-51cb-4808-a9ef-875568bde54aeviluuid", 54 "26695g10-a384-48e7-8867-6d48b7fae80a", // not valid UUID, but starts with a number. 55 "superSkipper", 56 "SuperSkipper", 57 "083superskipper", 58 "茶", 59 "super skipper", 60 "100", 61 "10-09-2016", 62 "", 63 " ", 64 "-", 65 "_", 66 "no--duplication", 67 "no---duplication", 68 "endswithadash-", 69 "endswithasterisk*", 70 "internal*-asterisk", 71 } 72 for _, n := range tests { 73 assert.Error(t, ValidateServiceName(n), "Expected %q to be an invalid service name", n) 74 } 75 }