mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-04-11 17:47:20 +10:00
30 lines
788 B
Go
30 lines
788 B
Go
package option
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
"github.com/sagernet/sing/common/json"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDNSRuleActionRespondUnmarshalJSON(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var action DNSRuleAction
|
|
err := json.UnmarshalContext(context.Background(), []byte(`{"action":"respond"}`), &action)
|
|
require.NoError(t, err)
|
|
require.Equal(t, C.RuleActionTypeRespond, action.Action)
|
|
require.Equal(t, DNSRouteActionOptions{}, action.RouteOptions)
|
|
}
|
|
|
|
func TestDNSRuleActionRespondRejectsUnknownFields(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var action DNSRuleAction
|
|
err := json.UnmarshalContext(context.Background(), []byte(`{"action":"respond","disable_cache":true}`), &action)
|
|
require.ErrorContains(t, err, "unknown field")
|
|
}
|