Commit 99db2615 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Make GENERAL messages permanent

Also add fuzz testing for the parser.
parent 455743f2
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
package dclish

import (
	"testing"
)

// FuzzParseAndRun fuzzes the DCLish command parser.
func FuzzParseAndRun(f *testing.F) {
	commands := Commands{
		"SEND": {
			Action:  func(c *Command) error { return nil },
			MinArgs: 1,
			MaxArgs: 1,
			Flags: Flags{
				"/TO":     {OptArg: true, Default: "SYSTEM"},
				"/URGENT": {},
			},
		},
		"READ": {
			Commands: Commands{
				"NEW": {
					Action: func(c *Command) error { return nil },
				},
			},
		},
		"DIRECTORY": {
			Action: func(c *Command) error { return nil },
		},
		"REPLY": {
			Action:  func(c *Command) error { return nil },
			MaxArgs: 0,
			Flags: Flags{
				"/ALL": {},
			},
		},
	}
	commandTable := BuildCommandTable(commands)

	f.Add("SEND message.txt /TO=USER1")
	f.Add(`SEND "a message with spaces" /URGENT`)
	f.Add("READ NEW")
	f.Add("DIRECTORY /FULL")
	f.Add("REPLY /ALL /NOALL")
	f.Add("UNKNOWN COMMAND")
	f.Add(`SEND 'quoted string' /TO="another quoted"`)
	f.Add("SEND /")
	f.Add("SEND /TO=/URGENT")
	f.Add("")
	f.Add(" ")

	f.Fuzz(func(t *testing.T, input string) {
		_ = commandTable.ParseAndRun(input)
	})
}
+2 −2
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@ INSERT INTO users (login, name, admin, moderator)

-- SeedFolderGeneral adds the GENERAL folder.
-- name: SeedFolderGeneral :exec
INSERT INTO folders (name, owner, description, system, alert)
  VALUES ('GENERAL', 'SYSTEM', 'Default general bulletin folder.', 1, 2);
INSERT INTO folders (name, owner, description, system, alert, expire)
  VALUES ('GENERAL', 'SYSTEM', 'Default general bulletin folder.', 1, 2, -1);

-- SeedCreateMessage add in the initial messages.
-- name: SeedCreateMessage :exec
+4 −4
Original line number Diff line number Diff line
@@ -47,14 +47,14 @@ func (q *Queries) SeedCreateMessage(ctx context.Context, arg SeedCreateMessagePa
}

const seedFolderGeneral = `-- name: SeedFolderGeneral :exec
INSERT INTO folders (name, owner, description, system, alert)
  VALUES ('GENERAL', 'SYSTEM', 'Default general bulletin folder.', 1, 2)
INSERT INTO folders (name, owner, description, system, alert, expire)
  VALUES ('GENERAL', 'SYSTEM', 'Default general bulletin folder.', 1, 2, -1)
`

// SeedFolderGeneral adds the GENERAL folder.
//
//	INSERT INTO folders (name, owner, description, system, alert)
//	  VALUES ('GENERAL', 'SYSTEM', 'Default general bulletin folder.', 1, 2)
//	INSERT INTO folders (name, owner, description, system, alert, expire)
//	  VALUES ('GENERAL', 'SYSTEM', 'Default general bulletin folder.', 1, 2, -1)
func (q *Queries) SeedFolderGeneral(ctx context.Context) error {
	_, err := q.db.ExecContext(ctx, seedFolderGeneral)
	return err