Skip to content

Commit

Permalink
Merge pull request #125 from OctopusDeploy/chore/update-test-workflow
Browse files Browse the repository at this point in the history
* chore: added integration tests
  • Loading branch information
jbristowe authored Jul 27, 2022
2 parents 88184c9 + 1b67622 commit ebf968c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 33 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,40 @@ on:
defaults:
run:
shell: bash
env:
SA_PASSWORD: ${{ secrets.DB_IMAGE_SA_PASSWORD }}
ADMIN_API_KEY: ${{ secrets.OD_IMAGE_ADMIN_API_KEY }}
SERVER_URL: 'http://localhost:8080'
jobs:
test:
runs-on: ubuntu-latest
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: ${{ env.SA_PASSWORD }}
MSSQL_PID: Developer
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P \"$SA_PASSWORD\" -Q \"SELECT 1\" || exit 1"
--health-interval 10s
--health-timeout 3s
--health-retries 10
--health-start-period 10s
octopusserver:
image: octopusdeploy/octopusdeploy
env:
ACCEPT_EULA: Y
DB_CONNECTION_STRING: 'Server=sqlserver;Database=OctopusDeploy;User Id=sa;Password=${{ env.SA_PASSWORD }};'
ADMIN_API_KEY: ${{ env.ADMIN_API_KEY }}
ENABLE_USAGE: N
OCTOPUS_SERVER_BASE64_LICENSE: ${{ secrets.OCTOPUS_SERVER_BASE64_LICENSE }}
ports:
- 8080:8080
# https://github.com/dorny/test-reporter/issues/168
permissions:
statuses: write
checks: write
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -20,4 +51,10 @@ jobs:
run: go build -a -race -v ./...
- name: Vet
run: go vet -v ./...
# TODO: added unit and integration tests that use the Docker container running Octopus
- run: |
curl '${{ env.SERVER_URL }}/api/configuration/webportal/values' -X 'PUT' -H 'Content-Type: application/json' -H 'X-Octopus-ApiKey: ${{ env.ADMIN_API_KEY }}' --data-binary '{"Security":{"CorsWhitelist":"http://localhost,${{ env.SERVER_URL }}","ReferrerPolicy":"no-referrer","ContentSecurityPolicyEnabled":true,"HttpStrictTransportSecurityEnabled":false,"HttpStrictTransportSecurityMaxAge":31556926,"XOptions":{"XFrameOptionAllowFrom":null,"XFrameOptions":"None"}}}' -o /dev/null -s -w "%{http_code}\n"
name: Add server url to CORS
- run: go test -v ./...
env:
OCTOPUS_HOST: ${{ env.SERVER_URL }}
OCTOPUS_API_KEY: ${{ env.ADMIN_API_KEY }}
15 changes: 8 additions & 7 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services"
"github.com/dghubble/sling"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewClient(t *testing.T) {
client := &http.Client{}
octopusURL := os.Getenv("OCTOPUS_URL")
apiKey := os.Getenv("OCTOPUS_APIKEY")
spaceID := os.Getenv("OCTOPUS_SPACE_ID")
octopusURL := os.Getenv("OCTOPUS_HOST")
apiKey := os.Getenv("OCTOPUS_API_KEY")
spaceID := os.Getenv("OCTOPUS_SPACE")

apiURL, err := url.Parse(octopusURL)
if err != nil {
Expand All @@ -43,13 +44,13 @@ func TestNewClient(t *testing.T) {
client, err := NewClient(tc.client, tc.url, tc.apiKey, tc.spaceID)

if !tc.isValid {
assert.Error(t, err)
assert.Nil(t, client)
require.Error(t, err)
require.Nil(t, client)
return
}

assert.NoError(t, err)
assert.NotNil(t, client)
require.NoError(t, err)
require.NotNil(t, client)
assert.NotNil(t, client.Accounts)
})
}
Expand Down
11 changes: 7 additions & 4 deletions test/e2e/release_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@ func TestReleaseServiceCreateV1(t *testing.T) {

releaseCreate := releases.NewCreateReleaseV1(space.Name, project.Name)
createReleaseResponse, err := client.Releases.CreateV1(releaseCreate)
require.NoError(t, err)
require.NotNil(t, createReleaseResponse)
require.NotNil(t, createReleaseResponse.ReleaseID)
require.NotNil(t, createReleaseResponse.ReleaseVersion)

// if HTTP 404 response then Executions API is unavailable
if err == nil {
require.NotNil(t, createReleaseResponse)
require.NotNil(t, createReleaseResponse.ReleaseID)
require.NotNil(t, createReleaseResponse.ReleaseVersion)
}
}

func TestReleaseServiceGetByID(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/tag_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestTagServiceAddGetDelete(t *testing.T) {
require.NotNil(t, updatedTagSet)
require.NoError(t, err)

tagToCompare := updatedTagSet.Tags[0]
require.NotNil(t, tagToCompare)
IsEqualTags(t, tag, tagToCompare)
tagSetToCompare, err := client.TagSets.GetByID(updatedTagSet.GetID())
require.NotNil(t, tagSetToCompare)
require.NoError(t, err)
IsEqualTags(t, updatedTagSet.Tags[0], tagSetToCompare.Tags[0])
}
35 changes: 17 additions & 18 deletions test/resources/display_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,30 @@ func TestDisplaySettingsAsJson(t *testing.T) {
require.NotNil(t, displaySettingsAsJson)

jsonassert.New(t).Assertf(expectedJson, string(displaySettingsAsJson))
}

option1 := "Option-1"
value1 := "Value-1"
option2 := "Option-2"
value2 := "Value-2"
option3 := "Option-3"
value3 := "Value-3"

selectOptions := map[string]string{}
selectOptions[value1] = option1
selectOptions[value2] = option2
selectOptions[value3] = option3
func TestSelectOptions(t *testing.T) {
controlType := "Select"
option1 := internal.GetRandomName()
value1 := internal.GetRandomName()
option2 := internal.GetRandomName()
value2 := internal.GetRandomName()
option3 := internal.GetRandomName()
value3 := internal.GetRandomName()

displaySettings = variables.NewDisplaySettings(controlType, selectOptions)
selectOptions := map[string]string{
option1: value1,
option2: value2,
option3: value3,
}

expectedJson = fmt.Sprintf(`{
"Octopus.ControlType": "%s",
"Octopus.SelectOptions": "Value-1|Option-1\nValue-2|Option-2\nValue-3|Option-3"
}`, controlType)
displaySettings := variables.NewDisplaySettings(controlType, selectOptions)

displaySettingsAsJson, err = json.Marshal(displaySettings)
displaySettingsAsJson, err := json.Marshal(displaySettings)
require.NoError(t, err)
require.NotNil(t, displaySettingsAsJson)

jsonassert.New(t).Assertf(string(displaySettingsAsJson), expectedJson)
// TODO: loop through each select option; verify count and option/value pairs
}

func TestDisplaySettingsFromJson(t *testing.T) {
Expand Down

0 comments on commit ebf968c

Please sign in to comment.