aboutsummaryrefslogtreecommitdiff
path: root/internal/pushrules/action_test.go
blob: 72db9c998a2b94630a490780d8ab756bca4bda5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package pushrules

import (
	"encoding/json"
	"fmt"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestActionJSON(t *testing.T) {
	tsts := []struct {
		Want Action
	}{
		{Action{Kind: NotifyAction}},
		{Action{Kind: DontNotifyAction}},
		{Action{Kind: CoalesceAction}},
		{Action{Kind: SetTweakAction}},

		{Action{Kind: SetTweakAction, Tweak: SoundTweak, Value: "default"}},
		{Action{Kind: SetTweakAction, Tweak: HighlightTweak}},
		{Action{Kind: SetTweakAction, Tweak: HighlightTweak, Value: "false"}},
	}
	for _, tst := range tsts {
		t.Run(fmt.Sprintf("%+v", tst.Want), func(t *testing.T) {
			bs, err := json.Marshal(&tst.Want)
			if err != nil {
				t.Fatalf("Marshal failed: %v", err)
			}
			var got Action
			if err := json.Unmarshal(bs, &got); err != nil {
				t.Fatalf("Unmarshal failed: %v", err)
			}
			if diff := cmp.Diff(tst.Want, got); diff != "" {
				t.Errorf("+got -want:\n%s", diff)
			}
		})
	}
}