github.com/projectcontour/contour@v1.28.2/cmd/contour/contour_test.go (about) 1 // Copyright Project Contour Authors 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package main 15 16 import ( 17 "sort" 18 "testing" 19 20 "github.com/alecthomas/kingpin/v2" 21 "github.com/sirupsen/logrus" 22 "github.com/stretchr/testify/assert" 23 ) 24 25 func assertOptionFlagsAreSorted(t *testing.T, cmd *kingpin.CmdClause) { 26 var flags []string 27 28 for _, v := range cmd.Model().FlagGroupModel.Flags { 29 flags = append(flags, v.Name) 30 } 31 assert.Truef(t, sort.StringsAreSorted(flags), "the flags for subcommand %q aren't sorted: %v", cmd.Model().Name, flags) 32 } 33 34 func TestOptionFlagsAreSorted(t *testing.T) { 35 app := kingpin.New("contour_option_flags_are_sorted", "Assert contour options are sorted") 36 log := logrus.StandardLogger() 37 38 bootstrap, _ := registerBootstrap(app) 39 assertOptionFlagsAreSorted(t, bootstrap) 40 41 certgen, _ := registerCertGen(app) 42 assertOptionFlagsAreSorted(t, certgen) 43 44 cli, _ := registerCli(app, log) 45 assertOptionFlagsAreSorted(t, cli) 46 47 envoyCmd := app.Command("envoy", "Sub-command for envoy actions.") 48 49 sdmShutdown, _ := registerShutdown(envoyCmd, log) 50 assertOptionFlagsAreSorted(t, sdmShutdown) 51 52 sdm, _ := registerShutdownManager(envoyCmd, log) 53 assertOptionFlagsAreSorted(t, sdm) 54 55 gatewayProvisioner, _ := registerGatewayProvisioner(app) 56 assertOptionFlagsAreSorted(t, gatewayProvisioner) 57 58 serve, _ := registerServe(app) 59 assertOptionFlagsAreSorted(t, serve) 60 }