(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestInitializeCmd(t *testing.T) { |
| 31 | cases := []struct { |
| 32 | name string |
| 33 | args []string |
| 34 | expectedRoot string |
| 35 | expectedMirror string |
| 36 | }{ |
| 37 | { |
| 38 | name: "no args", |
| 39 | expectedMirror: "https://tuf-repo-cdn.sigstore.dev", |
| 40 | }, |
| 41 | { |
| 42 | name: "with root", |
| 43 | args: []string{"--root", "/some/path/root.json"}, |
| 44 | expectedRoot: "/some/path/root.json", |
| 45 | expectedMirror: "https://tuf-repo-cdn.sigstore.dev", |
| 46 | }, |
| 47 | { |
| 48 | name: "with mirror", |
| 49 | args: []string{"--mirror", "https://tuf.local"}, |
| 50 | expectedMirror: "https://tuf.local", |
| 51 | }, |
| 52 | { |
| 53 | name: "with root and mirror", |
| 54 | args: []string{"--root", "/some/path/root.json", "--mirror", "https://tuf.local"}, |
| 55 | expectedRoot: "/some/path/root.json", |
| 56 | expectedMirror: "https://tuf.local", |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | for _, tt := range cases { |
| 61 | t.Run(tt.name, func(t *testing.T) { |
| 62 | initF := func(ctx context.Context, root, mirror string) error { |
| 63 | require.Equal(t, tt.expectedRoot, root) |
| 64 | require.Equal(t, tt.expectedMirror, mirror) |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | sigInitCmd := sigstoreInitializeCmd(initF) |
| 69 | |
| 70 | sigCmd := NewSigstoreCmd() |
| 71 | sigCmd.AddCommand(sigInitCmd) |
| 72 | |
| 73 | rootCmd := root.NewRootCmd() |
| 74 | rootCmd.AddCommand(sigCmd) |
| 75 | |
| 76 | rootCmd.SetContext(context.Background()) |
| 77 | rootCmd.SetArgs(append([]string{"sigstore", "initialize"}, tt.args...)) |
| 78 | |
| 79 | err := rootCmd.Execute() |
| 80 | require.NoError(t, err) |
| 81 | }) |
| 82 | } |
| 83 | } |
nothing calls this directly
no test coverage detected