github.com/newrelic/newrelic-client-go@v1.1.0/pkg/apm/deployments_test.go (about)

     1  //go:build unit
     2  // +build unit
     3  
     4  package apm
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  var (
    14  	testListDeploymentsResponseJSON = `{
    15  		"deployments": [
    16  			{
    17  				"id": 123,
    18  				"revision": "master",
    19  				"changelog": "v0.0.1",
    20  				"description": "testing",
    21  				"user": "foo",
    22  				"timestamp": "2019-12-27T19:13:23+00:00",
    23  				"links": {
    24  					"application": 111
    25  				}
    26  			}
    27  		]
    28  	}`
    29  
    30  	testDeploymentJSON = `{
    31  		"deployment": {
    32  			"id": 321,
    33  			"revision": "master",
    34  			"changelog": "v0.0.1",
    35  			"description": "testing",
    36  			"user": "foo",
    37  			"timestamp": "2019-12-27T19:13:23+00:00",
    38  			"links": {
    39  				"application": 222
    40  			}
    41  		}
    42  	}`
    43  )
    44  
    45  func TestListDeployments(t *testing.T) {
    46  	t.Parallel()
    47  	apm := newMockResponse(t, testListDeploymentsResponseJSON, http.StatusOK)
    48  
    49  	expected := []*Deployment{
    50  		{
    51  			ID:          123,
    52  			Revision:    "master",
    53  			Changelog:   "v0.0.1",
    54  			Description: "testing",
    55  			User:        "foo",
    56  			Timestamp:   "2019-12-27T19:13:23+00:00",
    57  			Links: &DeploymentLinks{
    58  				ApplicationID: 111,
    59  			},
    60  		},
    61  	}
    62  
    63  	actual, err := apm.ListDeployments(123)
    64  
    65  	assert.NoError(t, err)
    66  	assert.NotNil(t, actual)
    67  	assert.Equal(t, expected, actual)
    68  }
    69  
    70  func TestCreateDeployment(t *testing.T) {
    71  	t.Parallel()
    72  	apm := newMockResponse(t, testDeploymentJSON, http.StatusCreated)
    73  
    74  	deployment := Deployment{
    75  		Revision:    "master",
    76  		Changelog:   "v0.0.1",
    77  		Description: "testing",
    78  		User:        "foo",
    79  	}
    80  
    81  	expected := &Deployment{
    82  		ID:          321,
    83  		Revision:    "master",
    84  		Changelog:   "v0.0.1",
    85  		Description: "testing",
    86  		User:        "foo",
    87  		Timestamp:   "2019-12-27T19:13:23+00:00",
    88  		Links: &DeploymentLinks{
    89  			ApplicationID: 222,
    90  		},
    91  	}
    92  
    93  	actual, err := apm.CreateDeployment(111, deployment)
    94  
    95  	assert.NoError(t, err)
    96  	assert.NotNil(t, actual)
    97  	assert.Equal(t, expected, actual)
    98  }
    99  
   100  func TestDeleteDeployment(t *testing.T) {
   101  	t.Parallel()
   102  	apm := newMockResponse(t, testDeploymentJSON, http.StatusCreated)
   103  
   104  	expected := &Deployment{
   105  		ID:          321,
   106  		Revision:    "master",
   107  		Changelog:   "v0.0.1",
   108  		Description: "testing",
   109  		User:        "foo",
   110  		Timestamp:   "2019-12-27T19:13:23+00:00",
   111  		Links: &DeploymentLinks{
   112  			ApplicationID: 222,
   113  		},
   114  	}
   115  
   116  	actual, err := apm.DeleteDeployment(222, 321)
   117  
   118  	assert.NoError(t, err)
   119  	assert.NotNil(t, actual)
   120  	assert.Equal(t, expected, actual)
   121  }