|
| 1 | +package api |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/Dobefu/csb/cmd/cs_sdk" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func setupDeleteGlobalFieldTest() func() { |
| 12 | + return func() { |
| 13 | + csSdkRequest = cs_sdk.Request |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +func TestDeleteGlobalFieldSuccess(t *testing.T) { |
| 18 | + cleanup := setupDeleteGlobalFieldTest() |
| 19 | + defer cleanup() |
| 20 | + |
| 21 | + csSdkRequest = func(path string, method string, body map[string]interface{}, useManagementToken bool) (map[string]interface{}, error) { |
| 22 | + return map[string]interface{}{}, nil |
| 23 | + } |
| 24 | + |
| 25 | + err := DeleteGlobalField("Test Name", false) |
| 26 | + assert.NoError(t, err) |
| 27 | +} |
| 28 | + |
| 29 | +func TestDeleteGlobalFieldErrDoesNotExist(t *testing.T) { |
| 30 | + cleanup := setupDeleteGlobalFieldTest() |
| 31 | + defer cleanup() |
| 32 | + |
| 33 | + csSdkRequest = func(path string, method string, body map[string]interface{}, useManagementToken bool) (map[string]interface{}, error) { |
| 34 | + if method == "GET" { |
| 35 | + return nil, errors.New("cannot find global field") |
| 36 | + } |
| 37 | + |
| 38 | + return map[string]interface{}{}, nil |
| 39 | + } |
| 40 | + |
| 41 | + err := DeleteGlobalField("Bogus", false) |
| 42 | + assert.EqualError(t, err, "the global field does not exist") |
| 43 | +} |
| 44 | + |
| 45 | +func TestDeleteGlobalFieldErrDelete(t *testing.T) { |
| 46 | + cleanup := setupDeleteGlobalFieldTest() |
| 47 | + defer cleanup() |
| 48 | + |
| 49 | + csSdkRequest = func(path string, method string, body map[string]interface{}, useManagementToken bool) (map[string]interface{}, error) { |
| 50 | + if method == "DELETE" { |
| 51 | + return nil, errors.New("cannot find global field") |
| 52 | + } |
| 53 | + |
| 54 | + return map[string]interface{}{}, nil |
| 55 | + } |
| 56 | + |
| 57 | + err := DeleteGlobalField("Test Name", false) |
| 58 | + assert.EqualError(t, err, "cannot find global field") |
| 59 | +} |
0 commit comments