github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/services/wireguard/endpoint/proxyclient/client_test.go (about) 1 /* 2 * Copyright (C) 2022 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package proxyclient 19 20 import ( 21 "net" 22 "testing" 23 24 "github.com/mysteriumnetwork/node/services/wireguard/wgcfg" 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func Test_ConfigureDevice_ConfigureErrors(t *testing.T) { 29 30 client, err := New() 31 assert.NoError(t, err) 32 33 tests := []struct { 34 name string 35 config wgcfg.DeviceConfig 36 expected string 37 }{ 38 { 39 name: "empty config", 40 config: wgcfg.DeviceConfig{}, 41 expected: "could not parse local addr", 42 }, 43 { 44 name: "DNS list not provided", 45 config: wgcfg.DeviceConfig{ 46 Subnet: net.IPNet{IP: net.ParseIP("10.0.182.2"), Mask: net.IPv4Mask(255, 255, 255, 0)}, 47 DNS: []string{}, 48 }, 49 expected: "DNS addr list is empty", 50 }, 51 { 52 name: "DNS list contain empty value", 53 config: wgcfg.DeviceConfig{ 54 Subnet: net.IPNet{IP: net.ParseIP("10.0.182.2"), Mask: net.IPv4Mask(255, 255, 255, 0)}, 55 DNS: []string{""}, 56 }, 57 expected: "could not parse DNS addr", 58 }, 59 } 60 for _, test := range tests { 61 t.Run(test.name, func(t *testing.T) { 62 assert.ErrorContains(t, client.ConfigureDevice(test.config), test.expected) 63 }) 64 } 65 }