|
| 1 | +// Copyright © 2018 github.com/devopsctl authors |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 7 | +// furnished to do so, subject to the following conditions: |
| 8 | +// |
| 9 | +// The above copyright notice and this permission notice shall be included in |
| 10 | +// all copies or substantial portions of the Software. |
| 11 | +// |
| 12 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | +// THE SOFTWARE. |
| 19 | + |
| 20 | +package cmd |
| 21 | + |
| 22 | +import ( |
| 23 | + "testing" |
| 24 | + |
| 25 | + gitlab "github.com/xanzy/go-gitlab" |
| 26 | +) |
| 27 | + |
| 28 | +func TestDeleteTagCmd(t *testing.T) { |
| 29 | + tt := []struct { |
| 30 | + name string |
| 31 | + flagsMap map[string]string |
| 32 | + args []string |
| 33 | + expect testResult |
| 34 | + }{ |
| 35 | + { |
| 36 | + name: "delete an existent tag", |
| 37 | + flagsMap: map[string]string{ |
| 38 | + "project": "Group1/project1", |
| 39 | + }, |
| 40 | + args: []string{"sample_5.0"}, |
| 41 | + expect: pass, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "delete a non existent tag fails", |
| 45 | + flagsMap: map[string]string{ |
| 46 | + "project": "Group1/project1", |
| 47 | + }, |
| 48 | + args: []string{"nil-tag"}, |
| 49 | + expect: fail, |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + for _, tc := range tt { |
| 54 | + // SETUP |
| 55 | + // Create tag before deleting |
| 56 | + if tc.expect == pass { |
| 57 | + if _, err := newTag(tc.flagsMap["project"], |
| 58 | + &gitlab.CreateTagOptions{ |
| 59 | + TagName: gitlab.String(tc.args[0]), |
| 60 | + Ref: gitlab.String("master"), |
| 61 | + }); err != nil { |
| 62 | + tInfo(err) |
| 63 | + } |
| 64 | + } |
| 65 | + t.Run(tc.name, func(t *testing.T) { |
| 66 | + execT := execTestCmdFlags{ |
| 67 | + t: t, |
| 68 | + cmd: deleteTagCmd, |
| 69 | + flagsMap: tc.flagsMap, |
| 70 | + args: tc.args, |
| 71 | + } |
| 72 | + stdout, execResult := execT.executeCommand() |
| 73 | + assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout)) |
| 74 | + }) |
| 75 | + } |
| 76 | +} |
0 commit comments