github.com/hashicorp/vault/sdk@v0.11.0/helper/testhelpers/output_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package testhelpers
     5  
     6  import (
     7  	"fmt"
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestToMap(t *testing.T) {
    13  	type s struct {
    14  		A string            `json:"a"`
    15  		B []byte            `json:"b"`
    16  		C map[string]string `json:"c"`
    17  		D string            `json:"-"`
    18  	}
    19  	type args struct {
    20  		in s
    21  	}
    22  	tests := []struct {
    23  		name    string
    24  		args    args
    25  		want    string
    26  		wantErr bool
    27  	}{
    28  		{
    29  			name:    "basic",
    30  			args:    args{s{A: "a", B: []byte("bytes"), C: map[string]string{"k": "v"}, D: "d"}},
    31  			want:    "map[a:a b:277089d91c0bdf4f2e6862ba7e4a07605119431f5d13f726dd352b06f1b206a9 c:map[k:v]]",
    32  			wantErr: false,
    33  		},
    34  	}
    35  	for _, tt := range tests {
    36  		t.Run(tt.name, func(t *testing.T) {
    37  			m, err := ToMap(&tt.args.in)
    38  			if (err != nil) != tt.wantErr {
    39  				t.Errorf("ToMap() error = %v, wantErr %v", err, tt.wantErr)
    40  				return
    41  			}
    42  			got := fmt.Sprintf("%s", m)
    43  			if !reflect.DeepEqual(got, tt.want) {
    44  				t.Errorf("ToMap() got = %v, want %v", got, tt.want)
    45  			}
    46  		})
    47  	}
    48  }