summaryrefslogtreecommitdiff
path: root/internal/config/v2/v2_test.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-02-06 16:26:59 +0100
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-02-19 14:15:07 +0100
commit3152078aec8334357a61171838f664eb03299211 (patch)
tree57da9dd39a70e44f05f104adc442b0166053b85c /internal/config/v2/v2_test.go
parent819d7f9914cbb34abb76b932c05b030a34986ec2 (diff)
Config: New state file
Caches less. Also convert the V1 state file
Diffstat (limited to 'internal/config/v2/v2_test.go')
-rw-r--r--internal/config/v2/v2_test.go139
1 files changed, 139 insertions, 0 deletions
diff --git a/internal/config/v2/v2_test.go b/internal/config/v2/v2_test.go
new file mode 100644
index 0000000..5a4c2ea
--- /dev/null
+++ b/internal/config/v2/v2_test.go
@@ -0,0 +1,139 @@
+package v2
+
+import (
+ "encoding/json"
+ "reflect"
+ "testing"
+
+ "github.com/eduvpn/eduvpn-common/internal/test"
+ "github.com/eduvpn/eduvpn-common/types/server"
+)
+
+func TestLoad(t *testing.T) {
+ cases := []struct {
+ json string
+ want *V2
+ wantErr string
+ }{
+ // normal v2 config
+ {
+ json: `
+{
+ "server_list": {
+ "1,a": {
+ "profiles": {
+ "current": "a",
+ "map": {
+ "a": {
+ "display_name": {
+ "en": "a"
+ }
+ }
+ }
+ }
+ }
+ }
+}
+`,
+ want: &V2{
+ List: map[ServerType]*Server{
+ {ID: "a", T: server.TypeInstituteAccess}: {
+ Profiles: server.Profiles{
+ Map: map[string]server.Profile{
+ "a": {DisplayName: map[string]string{"en": "a"}},
+ },
+ Current: "a",
+ },
+ },
+ },
+ },
+ wantErr: "",
+ },
+ {
+ json: `
+{
+ "server_list": {
+ "a,1": {
+ "profiles": {
+ "current": "a",
+ "map": {
+ "a": {
+ "display_name": {
+ "en": "a"
+ }
+ }
+ }
+ }
+ }
+ }
+}
+`,
+ want: nil,
+ wantErr: "expected integer",
+ },
+ {
+ json: `
+{
+ "server_list": {
+ "1,a": {
+ "profiles": {
+ "current": "a",
+ "map": {
+ "a": {
+ "display_name": {
+ "en": "a"
+ }
+ }
+ }
+ }
+ },
+ "2,a": {
+ "profiles": {
+ "current": "a",
+ "map": {
+ "a": {
+ "display_name": {
+ "en": "a"
+ }
+ }
+ }
+ }
+ }
+ }
+}
+`,
+ want: &V2{
+ List: map[ServerType]*Server{
+ {ID: "a", T: server.TypeInstituteAccess}: {
+ Profiles: server.Profiles{
+ Map: map[string]server.Profile{
+ "a": {DisplayName: map[string]string{"en": "a"}},
+ },
+ Current: "a",
+ },
+ },
+ {ID: "a", T: server.TypeSecureInternet}: {
+ Profiles: server.Profiles{
+ Map: map[string]server.Profile{
+ "a": {DisplayName: map[string]string{"en": "a"}},
+ },
+ Current: "a",
+ },
+ },
+ },
+ },
+ wantErr: "",
+ },
+ }
+
+ for _, v := range cases {
+ var g *V2
+ err := json.Unmarshal([]byte(v.json), &g)
+ test.AssertError(t, err, v.wantErr)
+ if err == nil {
+ if !reflect.DeepEqual(g, v.want) {
+ t.Fatalf("structs not equal")
+ }
+ }
+ }
+}