mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
This commit is contained in:
committed by
GitHub
parent
9021471cee
commit
c8cf89b52d
69
command/base_test.go
Normal file
69
command/base_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func getDefaultCliHeaders(t *testing.T) http.Header {
|
||||
bc := &BaseCommand{}
|
||||
cli, err := bc.Client()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cli.Headers()
|
||||
}
|
||||
|
||||
func TestClient_FlagHeader(t *testing.T) {
|
||||
defaultHeaders := getDefaultCliHeaders(t)
|
||||
|
||||
cases := []struct {
|
||||
Input map[string]string
|
||||
Valid bool
|
||||
}{
|
||||
{
|
||||
map[string]string{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
map[string]string{"foo": "bar", "header2": "value2"},
|
||||
true,
|
||||
},
|
||||
{
|
||||
map[string]string{"X-Vault-foo": "bar", "header2": "value2"},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
expectedHeaders := defaultHeaders.Clone()
|
||||
for key, val := range tc.Input {
|
||||
expectedHeaders.Add(key, val)
|
||||
}
|
||||
|
||||
bc := &BaseCommand{flagHeader: tc.Input}
|
||||
cli, err := bc.Client()
|
||||
|
||||
if err == nil && !tc.Valid {
|
||||
t.Errorf("No error for input[%#v], but not valid", tc.Input)
|
||||
continue
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if tc.Valid {
|
||||
t.Errorf("Error[%v] with input[%#v], but valid", err, tc.Input)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if cli == nil {
|
||||
t.Error("client should not be nil")
|
||||
}
|
||||
|
||||
actualHeaders := cli.Headers()
|
||||
if !reflect.DeepEqual(expectedHeaders, actualHeaders) {
|
||||
t.Errorf("expected [%#v] but got [%#v]", expectedHeaders, actualHeaders)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user