mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-17 05:01:35 +03:00
4508ae860e
Squashed commit of the following:
commit a0527b86f10596a86357630117607a3c507e4ac2
Merge: 512edaf2d 9694f19ef
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Jan 17 13:15:18 2024 +0300
Merge branch 'master' into AG-27492-client-persistent-ids
commit 512edaf2dc29f19c4fb7860b0c350a5e4180cda4
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Mon Jan 15 15:50:28 2024 +0300
home: imp docs
commit 4d4b3599918aab8ee6315c7f2f35f70db89e4d02
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jan 11 20:20:42 2024 +0300
home: imp code
commit 8031347b8613cc49a80968e162dd198851eafe7c
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jan 11 18:46:20 2024 +0300
home: fix typo
commit 5932b181fe6a0c0bc605070fd9ddcc6617703ab7
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jan 11 16:52:49 2024 +0300
home: imp code more
commit 9412f5846795acfb68b009491b1045d1e27d8ddc
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Jan 11 15:41:23 2024 +0300
home: imp code
commit 855d3201ab1b176ed5fdd32bce933a7795601a6d
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Jan 10 20:24:49 2024 +0300
home: add tests
commit 112f1bd13acf992b0ba9562c29365b22d5374ec2
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Fri Dec 29 18:29:11 2023 +0300
home: imp code
commit 8b295bfa8968c3767bcfaf05c7f109d75af8c961
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Fri Dec 29 14:58:17 2023 +0300
home: persistent client ids
125 lines
2.9 KiB
Go
125 lines
2.9 KiB
Go
package home
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPersistentClient_EqualIDs(t *testing.T) {
|
|
const (
|
|
ip = "0.0.0.0"
|
|
ip1 = "1.1.1.1"
|
|
ip2 = "2.2.2.2"
|
|
|
|
cidr = "0.0.0.0/0"
|
|
cidr1 = "1.1.1.1/11"
|
|
cidr2 = "2.2.2.2/22"
|
|
|
|
mac = "00-00-00-00-00-00"
|
|
mac1 = "11-11-11-11-11-11"
|
|
mac2 = "22-22-22-22-22-22"
|
|
|
|
cli = "client0"
|
|
cli1 = "client1"
|
|
cli2 = "client2"
|
|
)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
ids []string
|
|
prevIDs []string
|
|
want assert.BoolAssertionFunc
|
|
}{{
|
|
name: "single_ip",
|
|
ids: []string{ip1},
|
|
prevIDs: []string{ip1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "single_ip_not_equal",
|
|
ids: []string{ip1},
|
|
prevIDs: []string{ip2},
|
|
want: assert.False,
|
|
}, {
|
|
name: "ips_not_equal",
|
|
ids: []string{ip1, ip2},
|
|
prevIDs: []string{ip1, ip},
|
|
want: assert.False,
|
|
}, {
|
|
name: "ips_mixed_equal",
|
|
ids: []string{ip1, ip2},
|
|
prevIDs: []string{ip2, ip1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "single_subnet",
|
|
ids: []string{cidr1},
|
|
prevIDs: []string{cidr1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "subnets_not_equal",
|
|
ids: []string{ip1, ip2, cidr1, cidr2},
|
|
prevIDs: []string{ip1, ip2, cidr1, cidr},
|
|
want: assert.False,
|
|
}, {
|
|
name: "subnets_mixed_equal",
|
|
ids: []string{ip1, ip2, cidr1, cidr2},
|
|
prevIDs: []string{cidr2, cidr1, ip2, ip1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "single_mac",
|
|
ids: []string{mac1},
|
|
prevIDs: []string{mac1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "single_mac_not_equal",
|
|
ids: []string{mac1},
|
|
prevIDs: []string{mac2},
|
|
want: assert.False,
|
|
}, {
|
|
name: "macs_not_equal",
|
|
ids: []string{ip1, ip2, cidr1, cidr2, mac1, mac2},
|
|
prevIDs: []string{ip1, ip2, cidr1, cidr2, mac1, mac},
|
|
want: assert.False,
|
|
}, {
|
|
name: "macs_mixed_equal",
|
|
ids: []string{ip1, ip2, cidr1, cidr2, mac1, mac2},
|
|
prevIDs: []string{mac2, mac1, cidr2, cidr1, ip2, ip1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "single_client_id",
|
|
ids: []string{cli1},
|
|
prevIDs: []string{cli1},
|
|
want: assert.True,
|
|
}, {
|
|
name: "single_client_id_not_equal",
|
|
ids: []string{cli1},
|
|
prevIDs: []string{cli2},
|
|
want: assert.False,
|
|
}, {
|
|
name: "client_ids_not_equal",
|
|
ids: []string{ip1, ip2, cidr1, cidr2, mac1, mac2, cli1, cli2},
|
|
prevIDs: []string{ip1, ip2, cidr1, cidr2, mac1, mac2, cli1, cli},
|
|
want: assert.False,
|
|
}, {
|
|
name: "client_ids_mixed_equal",
|
|
ids: []string{ip1, ip2, cidr1, cidr2, mac1, mac2, cli1, cli2},
|
|
prevIDs: []string{cli2, cli1, mac2, mac1, cidr2, cidr1, ip2, ip1},
|
|
want: assert.True,
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
c := &persistentClient{}
|
|
err := c.setIDs(tc.ids)
|
|
require.NoError(t, err)
|
|
|
|
prev := &persistentClient{}
|
|
err = prev.setIDs(tc.prevIDs)
|
|
require.NoError(t, err)
|
|
|
|
tc.want(t, c.equalIDs(prev))
|
|
})
|
|
}
|
|
}
|