package owrt import ( "testing" ) const ( redirectName = "Test" redirectIndex = -1 redirectSrc = "10.10.10.10/24" redirectTarget = "ACCEPT" redirectProto = "tcp" redirectSrcDIP = "1.1.1.1" redirectSrcDPort = "333" redirectDestIP = "10.10.10.10" redirectDestPort = "22" ) func TestFWRedirectCreate(t *testing.T) { exec := createMockExecutor("", "", 0) uci := NewUCIWithExecutor(exec, "") redirect := NewUCIFirewallRedirect(uci) redirect.Name = redirectName redirect.Index = redirectIndex redirect.Src = redirectSrc redirect.Target = redirectTarget redirect.Proto = redirectProto redirect.SrcDIP = redirectSrcDIP redirect.SrcDPort = redirectSrcDPort redirect.DestIP = redirectDestIP redirect.DestPort = redirectDestPort if redirect.Create().ReturnCode != 0 { t.Fatalf("UCIFirewallRedirect.Create() failed !") } } func TestFWRedirectUpdate(t *testing.T) { exec := createMockExecutor("", "", 0) uci := NewUCIWithExecutor(exec, "") redirect := NewUCIFirewallRedirect(uci) redirect.Name = redirectName redirect.Index = redirectIndex redirect.Src = redirectSrc redirect.Target = redirectTarget redirect.Proto = redirectProto redirect.SrcDIP = redirectSrcDIP redirect.SrcDPort = redirectSrcDPort redirect.DestIP = redirectDestIP redirect.DestPort = redirectDestPort if redirect.Create().ReturnCode != 0 { t.Fatalf("UCIFirewallRedirect.Create() failed !") } redirect.Name = "NewRedirect" if redirect.Update().ReturnCode != 0 { t.Fatalf("UCIFirewallRedirect.Update() failed !") } } func TestFWRedirectDelete(t *testing.T) { exec := createMockExecutor("", "", 0) uci := NewUCIWithExecutor(exec, "") redirect := NewUCIFirewallRedirect(uci) redirect.Name = redirectName redirect.Index = redirectIndex redirect.Src = redirectSrc redirect.Target = redirectTarget redirect.Proto = redirectProto redirect.SrcDIP = redirectSrcDIP redirect.SrcDPort = redirectSrcDPort redirect.DestIP = redirectDestIP redirect.DestPort = redirectDestPort if redirect.Delete().ReturnCode != 0 { t.Fatalf("UCIWirelessInterface.Delete() failed !") } }