(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestBackupsCreate(t *testing.T) { |
| 91 | t.Parallel() |
| 92 | |
| 93 | scenarios := []tests.ApiScenario{ |
| 94 | { |
| 95 | Name: "unauthorized", |
| 96 | Method: http.MethodPost, |
| 97 | URL: "/api/backups", |
| 98 | AfterTestFunc: func(t testing.TB, app *tests.TestApp, res *http.Response) { |
| 99 | ensureNoBackups(t, app) |
| 100 | }, |
| 101 | ExpectedStatus: 401, |
| 102 | ExpectedContent: []string{`"data":{}`}, |
| 103 | ExpectedEvents: map[string]int{"*": 0}, |
| 104 | }, |
| 105 | { |
| 106 | Name: "authorized as regular user", |
| 107 | Method: http.MethodPost, |
| 108 | URL: "/api/backups", |
| 109 | Headers: map[string]string{ |
| 110 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyNTI0NjA0NDYxLCJyZWZyZXNoYWJsZSI6dHJ1ZX0.ZT3F0Z3iM-xbGgSG3LEKiEzHrPHr8t8IuHLZGGNuxLo", |
| 111 | }, |
| 112 | AfterTestFunc: func(t testing.TB, app *tests.TestApp, res *http.Response) { |
| 113 | ensureNoBackups(t, app) |
| 114 | }, |
| 115 | ExpectedStatus: 403, |
| 116 | ExpectedContent: []string{`"data":{}`}, |
| 117 | ExpectedEvents: map[string]int{"*": 0}, |
| 118 | }, |
| 119 | { |
| 120 | Name: "authorized as superuser (pending backup)", |
| 121 | Method: http.MethodPost, |
| 122 | URL: "/api/backups", |
| 123 | Headers: map[string]string{ |
| 124 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY", |
| 125 | }, |
| 126 | BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) { |
| 127 | app.Store().Set(core.StoreKeyActiveBackup, "") |
| 128 | }, |
| 129 | AfterTestFunc: func(t testing.TB, app *tests.TestApp, res *http.Response) { |
| 130 | ensureNoBackups(t, app) |
| 131 | }, |
| 132 | ExpectedStatus: 400, |
| 133 | ExpectedContent: []string{`"data":{}`}, |
| 134 | ExpectedEvents: map[string]int{"*": 0}, |
| 135 | }, |
| 136 | { |
| 137 | Name: "authorized as superuser (autogenerated name)", |
| 138 | Method: http.MethodPost, |
| 139 | URL: "/api/backups", |
| 140 | Headers: map[string]string{ |
| 141 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY", |
| 142 | }, |
| 143 | AfterTestFunc: func(t testing.TB, app *tests.TestApp, res *http.Response) { |
| 144 | files, err := getBackupFiles(app) |
| 145 | if err != nil { |
| 146 | t.Fatal(err) |
| 147 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…