github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/rpc/client/headers_test.go (about) 1 package client 2 3 import ( 4 "context" 5 "net/http" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/twitchtv/twirp" 10 ) 11 12 func TestWithCustomHeaders(t *testing.T) { 13 type args struct { 14 ctx context.Context 15 customHeaders http.Header 16 } 17 tests := []struct { 18 name string 19 args args 20 want http.Header 21 }{ 22 { 23 name: "happy path", 24 args: args{ 25 ctx: context.Background(), 26 customHeaders: http.Header{ 27 "Trivy-Token": []string{"token"}, 28 }, 29 }, 30 want: http.Header{ 31 "Trivy-Token": []string{"token"}, 32 }, 33 }, 34 { 35 name: "sad path, invalid headers passed in", 36 args: args{ 37 ctx: context.Background(), 38 customHeaders: http.Header{ 39 "Content-Type": []string{"token"}, 40 }, 41 }, 42 want: http.Header(nil), 43 }, 44 } 45 for _, tt := range tests { 46 gotCtx := WithCustomHeaders(tt.args.ctx, tt.args.customHeaders) 47 header, _ := twirp.HTTPRequestHeaders(gotCtx) 48 assert.Equal(t, tt.want, header, tt.name) 49 } 50 }