From 188077d7fc8738ca794babf033de8441e18a9aa4 Mon Sep 17 00:00:00 2001 From: nathannaveen <42319948+nathannaveen@users.noreply.github.com> Date: Mon, 14 Mar 2022 10:55:25 -0400 Subject: [PATCH] Unit tests: dnsserver/https (#5251) - Added unit tests for dnsserver/https. Signed-off-by: nathannaveen <42319948+nathannaveen@users.noreply.github.com> --- core/dnsserver/https_test.go | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 core/dnsserver/https_test.go diff --git a/core/dnsserver/https_test.go b/core/dnsserver/https_test.go new file mode 100644 index 000000000..00ed366d7 --- /dev/null +++ b/core/dnsserver/https_test.go @@ -0,0 +1,90 @@ +package dnsserver + +import ( + "net" + "net/http" + "reflect" + "testing" +) + +func TestDoHWriter_LocalAddr(t *testing.T) { + tests := []struct { + name string + laddr net.Addr + want net.Addr + }{ + { + name: "LocalAddr", + laddr: &net.TCPAddr{}, + want: &net.TCPAddr{}, + }, + { + name: "LocalAddr", + laddr: &net.UDPAddr{}, + want: &net.UDPAddr{}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + d := &DoHWriter{ + laddr: tt.laddr, + } + if got := d.LocalAddr(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("LocalAddr() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDoHWriter_RemoteAddr(t *testing.T) { + tests := []struct { + name string + want net.Addr + raddr net.Addr + }{ + { + name: "RemoteAddr", + want: &net.TCPAddr{}, + raddr: &net.TCPAddr{}, + }, + { + name: "RemoteAddr", + want: &net.UDPAddr{}, + raddr: &net.UDPAddr{}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + d := &DoHWriter{ + raddr: tt.raddr, + } + if got := d.RemoteAddr(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("RemoteAddr() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestDoHWriter_Request(t *testing.T) { + tests := []struct { + name string + request *http.Request + want *http.Request + }{ + { + name: "Request", + request: &http.Request{}, + want: &http.Request{}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + d := &DoHWriter{ + request: tt.request, + } + if got := d.Request(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Request() = %v, want %v", got, tt.want) + } + }) + } +}