mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-25 08:08:18 +03:00
d40de33316
Squashed commit of the following: commit3191224d6d
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 26 18:20:04 2024 +0300 client: imp tests commit6cc4ed53a2
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 26 18:04:36 2024 +0300 client: imp code commit79272b299a
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 26 16:10:06 2024 +0300 all: imp code commit0a001fffbe
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 24 20:05:47 2024 +0300 all: imp tests commit80f7e98d30
Merge:df7492e9d
e338214ad
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 24 19:10:13 2024 +0300 Merge branch 'master' into AG-27492-client-storage-runtime-sources commitdf7492e9de
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 24 19:06:37 2024 +0300 all: imp code commit23896ae5a6
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 19 21:04:34 2024 +0300 client: fix typo commitba0ba2478c
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 19 21:02:13 2024 +0300 all: imp code commitf7315be742
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 12 14:35:38 2024 +0300 home: imp code commitf63d0e80fb
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 12 14:15:49 2024 +0300 all: imp code commit9feda414b6
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 10 17:53:42 2024 +0300 all: imp code commitfafd7cbb52
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Sep 9 21:13:05 2024 +0300 all: imp code commit2d2b8e0216
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Sep 5 20:55:10 2024 +0300 client: add tests commit4d394e6f21
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 29 20:40:38 2024 +0300 all: client storage runtime sources
124 lines
2.9 KiB
Go
124 lines
2.9 KiB
Go
package client
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPersistent_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 {
|
|
want assert.BoolAssertionFunc
|
|
name string
|
|
ids []string
|
|
prevIDs []string
|
|
}{{
|
|
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 := &Persistent{}
|
|
err := c.SetIDs(tc.ids)
|
|
require.NoError(t, err)
|
|
|
|
prev := &Persistent{}
|
|
err = prev.SetIDs(tc.prevIDs)
|
|
require.NoError(t, err)
|
|
|
|
tc.want(t, c.EqualIDs(prev))
|
|
})
|
|
}
|
|
}
|