From 0f27084f570995936fb63671ec247e70d4768808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 4 Mar 2021 15:01:59 +0100 Subject: [PATCH] Add flag parsing test for `api --template` --- pkg/cmd/api/api_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/cmd/api/api_test.go b/pkg/cmd/api/api_test.go index 16df36c20..75132d7b4 100644 --- a/pkg/cmd/api/api_test.go +++ b/pkg/cmd/api/api_test.go @@ -47,6 +47,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -66,6 +67,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -85,6 +87,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -104,6 +107,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -123,6 +127,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: true, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -142,6 +147,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: true, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -166,6 +172,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: true, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -190,6 +197,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -214,6 +222,7 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: 0, + Template: "", }, wantsErr: false, }, @@ -233,6 +242,27 @@ func Test_NewCmdApi(t *testing.T) { Paginate: false, Silent: false, CacheTTL: time.Minute * 5, + Template: "", + }, + wantsErr: false, + }, + { + name: "with template", + cli: "user -t 'hello {{.name}}'", + wants: ApiOptions{ + Hostname: "", + RequestMethod: "GET", + RequestMethodPassed: false, + RequestPath: "user", + RequestInputFile: "", + RawFields: []string(nil), + MagicFields: []string(nil), + RequestHeaders: []string(nil), + ShowResponseHeaders: false, + Paginate: false, + Silent: false, + CacheTTL: 0, + Template: "hello {{.name}}", }, wantsErr: false, }, @@ -270,6 +300,7 @@ func Test_NewCmdApi(t *testing.T) { assert.Equal(t, tt.wants.Paginate, opts.Paginate) assert.Equal(t, tt.wants.Silent, opts.Silent) assert.Equal(t, tt.wants.CacheTTL, opts.CacheTTL) + assert.Equal(t, tt.wants.Template, opts.Template) }) } }