(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestDeleteProjectHook(t *testing.T) { |
| 32 | tt := []struct { |
| 33 | name string |
| 34 | args []string |
| 35 | flagsMap map[string]string |
| 36 | expect testResult |
| 37 | }{ |
| 38 | { |
| 39 | name: "successfully delete a project hook", |
| 40 | flagsMap: map[string]string{ |
| 41 | "project": "23", |
| 42 | }, |
| 43 | expect: pass, |
| 44 | }, |
| 45 | { |
| 46 | name: "deleting a non existent project hook should fail", |
| 47 | args: []string{"55"}, |
| 48 | flagsMap: map[string]string{ |
| 49 | "project": "23", |
| 50 | }, |
| 51 | expect: fail, |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | for _, tc := range tt { |
| 56 | t.Run(tc.name, func(t *testing.T) { |
| 57 | // SETUP |
| 58 | // Create the project, get it's id for testing |
| 59 | if tc.expect == pass { |
| 60 | sampleHookURL := "http://example.com/" |
| 61 | hook, err := newProjectHook("23", &gitlab.AddProjectHookOptions{ |
| 62 | URL: &sampleHookURL, |
| 63 | }) |
| 64 | if err != nil { |
| 65 | tInfo(fmt.Sprintf("failed to create project hook %s", tc.args[0])) |
| 66 | } |
| 67 | tc.args = append(tc.args, strconv.Itoa(hook.ID)) |
| 68 | } |
| 69 | |
| 70 | execT := execTestCmdFlags{ |
| 71 | t: t, |
| 72 | cmd: deleteProjectHookCmd, |
| 73 | args: tc.args, |
| 74 | flagsMap: tc.flagsMap, |
| 75 | } |
| 76 | stdout, execResult := execT.executeCommand() |
| 77 | assertEqualResult(t, execResult, tc.expect, stdout) |
| 78 | // NOTE: assert positive test |
| 79 | // Validate the command output |
| 80 | if tc.expect == pass { |
| 81 | assertOutContains(t, stdout, "has been deleted") |
| 82 | } |
| 83 | }) |
| 84 | } |
| 85 | } |
nothing calls this directly
no test coverage detected