go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/gcloud/project_id_test.go (about) 1 // Copyright 2021 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gcloud 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 . "go.chromium.org/luci/common/testing/assertions" 22 ) 23 24 func TestValidateProjectID(t *testing.T) { 25 t.Parallel() 26 27 Convey(`Test ValidateProjectID`, t, func() { 28 Convey(`With valid project IDs`, func() { 29 So(ValidateProjectID(`project-id-foo`), ShouldBeNil) 30 }) 31 32 Convey(`W/o a starting, lowercase ASCII letters`, func() { 33 e := `must start with a lowercase ASCII letter` 34 So(ValidateProjectID(`0123456`), ShouldErrLike, e) 35 So(ValidateProjectID(`ProjectID`), ShouldErrLike, e) 36 So(ValidateProjectID(`-project-id`), ShouldErrLike, e) 37 So(ValidateProjectID(`ΓΆ-project-id`), ShouldErrLike, e) 38 }) 39 40 Convey(`With a trailing hyphen`, func() { 41 e := `must not have a trailing hyphen` 42 So(ValidateProjectID(`project-id-`), ShouldErrLike, e) 43 So(ValidateProjectID(`project--id--`), ShouldErrLike, e) 44 }) 45 46 Convey(`With len() < 6 or > 30`, func() { 47 e := `must contain 6 to 30 ASCII letters, digits, or hyphens` 48 So(ValidateProjectID(``), ShouldErrLike, e) 49 So(ValidateProjectID(`pro`), ShouldErrLike, e) 50 So(ValidateProjectID(`project-id-1234567890-1234567890`), ShouldErrLike, e) 51 }) 52 53 Convey(`With non-ascii letters`, func() { 54 e := `invalid letter` 55 So(ValidateProjectID(`project-β -id`), ShouldErrLike, e) 56 So(ValidateProjectID(`project-β -π`), ShouldErrLike, e) 57 So(ValidateProjectID(`project-id-ππππs`), ShouldErrLike, e) 58 }) 59 }) 60 }