Skip to content

Commit

Permalink
test(vpn): add test case for new vpn update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cad committed Sep 3, 2017
1 parent ee18b4c commit 27773c9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions vpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,46 @@ func TestVPNDeinit(t *testing.T) {
t.Errorf("revoked should be empty")
}
}
func TestVPNUpdate(t *testing.T) {
// Init:
setupTestCase()
CreateDB("sqlite3", ":memory:")
defer db.Cease()
// Prepare:
Init("localhost", "", UDPProto, "", "")
// Test:

var updatetests = []struct {
vpnnet string
dns string
vpnChanged bool
dnsChanged bool
}{
{"", "", false, false},
{"192.168.9.0/24", "", true, false},
{"", "2.2.2.2", false, true},
{"9.9.9.0/24", "1.1.1.1", true, true},
}
for _, tt := range updatetests {
server, err := GetServerInstance()
if err != nil {
t.Fatal(err)
}

oldIP := server.Net
oldDNS := server.DNS
Update(tt.vpnnet, tt.dns)
server = nil
server, err = GetServerInstance()
if (server.Net != oldIP) != tt.vpnChanged {
t.Fatalf("expected vpn change: %t but opposite happened", tt.vpnChanged)
}
if (server.DNS != oldDNS) != tt.dnsChanged {
t.Fatalf("expected vpn change: %t but opposite happened", tt.dnsChanged)
}
}

}

func TestVPNIsInitialized(t *testing.T) {
// Init:
Expand Down

0 comments on commit 27773c9

Please sign in to comment.