-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags_test.go
71 lines (64 loc) · 4.39 KB
/
flags_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright © 2024 Meroxa, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ecdysis
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
type testFlags struct {
Flag1 string `long:"flag1" short:"a" usage:"flag1 usage" required:"true" persistent:"false"`
Flag2 int `long:"flag2" short:"b" usage:"flag2 usage" required:"false" persistent:"true"`
Flag3 int8 `long:"flag3" short:"c" usage:"flag3 usage" required:"true" persistent:"false"`
Flag4 int16 `long:"flag4" short:"d" usage:"flag4 usage" required:"false" persistent:"true"`
Flag5 int32 `long:"flag5" short:"e" usage:"flag5 usage" required:"true" persistent:"false"`
Flag6 int64 `long:"flag6" short:"f" usage:"flag6 usage" required:"false" persistent:"true"`
Flag7 float32 `long:"flag7" short:"g" usage:"flag7 usage" required:"true" persistent:"false"`
Flag8 float64 `long:"flag8" short:"h" usage:"flag8 usage" required:"false" persistent:"true"`
Flag9 bool `long:"flag9" short:"i" usage:"flag9 usage" required:"true" persistent:"false"`
Flag10 time.Duration `long:"flag10" short:"j" usage:"flag10 usage" required:"false" persistent:"true"`
Flag11 []bool `long:"flag11" short:"k" usage:"flag11 usage" required:"true" persistent:"false"`
Flag12 []float32 `long:"flag12" short:"l" usage:"flag12 usage" required:"false" persistent:"true"`
Flag13 []float64 `long:"flag13" short:"m" usage:"flag13 usage" required:"true" persistent:"false"`
Flag14 []int32 `long:"flag14" short:"n" usage:"flag14 usage" required:"false" persistent:"true"`
Flag15 []int64 `long:"flag15" short:"o" usage:"flag15 usage" required:"true" persistent:"false"`
Flag16 []int `long:"flag16" short:"p" usage:"flag16 usage" required:"false" persistent:"true"`
Flag17 []string `long:"flag17" short:"q" usage:"flag17 usage" required:"true" persistent:"false"`
}
func TestBuildFlags(t *testing.T) {
flags := testFlags{}
want := Flags{
{Long: "flag1", Short: "a", Usage: "flag1 usage", Required: true, Persistent: false, Ptr: &flags.Flag1},
{Long: "flag2", Short: "b", Usage: "flag2 usage", Required: false, Persistent: true, Ptr: &flags.Flag2},
{Long: "flag3", Short: "c", Usage: "flag3 usage", Required: true, Persistent: false, Ptr: &flags.Flag3},
{Long: "flag4", Short: "d", Usage: "flag4 usage", Required: false, Persistent: true, Ptr: &flags.Flag4},
{Long: "flag5", Short: "e", Usage: "flag5 usage", Required: true, Persistent: false, Ptr: &flags.Flag5},
{Long: "flag6", Short: "f", Usage: "flag6 usage", Required: false, Persistent: true, Ptr: &flags.Flag6},
{Long: "flag7", Short: "g", Usage: "flag7 usage", Required: true, Persistent: false, Ptr: &flags.Flag7},
{Long: "flag8", Short: "h", Usage: "flag8 usage", Required: false, Persistent: true, Ptr: &flags.Flag8},
{Long: "flag9", Short: "i", Usage: "flag9 usage", Required: true, Persistent: false, Ptr: &flags.Flag9},
{Long: "flag10", Short: "j", Usage: "flag10 usage", Required: false, Persistent: true, Ptr: &flags.Flag10},
{Long: "flag11", Short: "k", Usage: "flag11 usage", Required: true, Persistent: false, Ptr: &flags.Flag11},
{Long: "flag12", Short: "l", Usage: "flag12 usage", Required: false, Persistent: true, Ptr: &flags.Flag12},
{Long: "flag13", Short: "m", Usage: "flag13 usage", Required: true, Persistent: false, Ptr: &flags.Flag13},
{Long: "flag14", Short: "n", Usage: "flag14 usage", Required: false, Persistent: true, Ptr: &flags.Flag14},
{Long: "flag15", Short: "o", Usage: "flag15 usage", Required: true, Persistent: false, Ptr: &flags.Flag15},
{Long: "flag16", Short: "p", Usage: "flag16 usage", Required: false, Persistent: true, Ptr: &flags.Flag16},
{Long: "flag17", Short: "q", Usage: "flag17 usage", Required: true, Persistent: false, Ptr: &flags.Flag17},
}
got := BuildFlags(&flags)
if diff := cmp.Diff(got, want); diff != "" {
t.Fatal(diff)
}
}