github.com/googleapis/api-linter@v1.65.2/cmd/api-linter/cli_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 6 "github.com/google/go-cmp/cmp" 7 ) 8 9 func TestNewCli(t *testing.T) { 10 tests := []struct { 11 name string 12 inputArgs []string 13 wantCli *cli 14 }{ 15 { 16 name: "AllFlags", 17 inputArgs: []string{ 18 "--config=config", 19 "--output-format=json", 20 "-o=out", 21 "--descriptor-set-in=proto_desc1", 22 "--descriptor-set-in=proto_desc2", 23 "--proto-path=proto_path_a", 24 "-I=proto_path_b", 25 "a.proto", 26 "b.proto", 27 }, 28 wantCli: &cli{ 29 ConfigPath: "config", 30 OutputPath: "out", 31 FormatType: "json", 32 ProtoDescPath: []string{"proto_desc1", "proto_desc2"}, 33 ProtoImportPaths: []string{"proto_path_a", "proto_path_b", "."}, 34 ProtoFiles: []string{"a.proto", "b.proto"}, 35 }, 36 }, 37 { 38 name: "ExitStatusOnLintFailure", 39 inputArgs: []string{ 40 "--set-exit-status", 41 }, 42 wantCli: &cli{ 43 ExitStatusOnLintFailure: true, 44 ProtoImportPaths: []string{"."}, 45 ProtoFiles: []string{}, 46 }, 47 }, 48 } 49 for _, test := range tests { 50 t.Run(test.name, func(t *testing.T) { 51 gotCli := newCli(test.inputArgs) 52 if diff := cmp.Diff(gotCli, test.wantCli); diff != "" { 53 t.Errorf("newCli() mismatch (-want +got):\n%s", diff) 54 } 55 }) 56 } 57 }