Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
Added Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StiviiK committed May 25, 2020
1 parent 7525b42 commit a236fc5
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 30 deletions.
1 change: 0 additions & 1 deletion .github/workflows/docker-build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

jobs:
build:
name: build-release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

jobs:
build:
name: build-release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/test.yaml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Unit Tests
on:
pull_request:
push:
branches:
- 'master'

jobs:
test_action_job:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Check out source code
uses: actions/checkout@v1
- name: Build
env:
GOPROXY: "https://proxy.golang.org"
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
run: go build -a -installsuffix cgo -ldflags="-w -s" .
- name: Test
env:
GOPROXY: "https://proxy.golang.org"
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
LOG_LEVEL: DEBUG
INPUT_CREDS: ${{ secrets.AZURE_CREDENTIALS }}
INPUT_RESOURCEGROUPNAME: azurearmaction
INPUT_TEMPLATELOCATION: ./test/template.json
INPUT_PARAMETERSLOCATION: ./test/parameters.json
INPUT_DEPLOYMENTNAME: github-test
INPUT_DEPLOYMENTMODE: Incremental
run: go test -v -failfast .
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sp.json
arm-action
__debug_bin
__debug_bin
run_tests.sh
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"LOG_LEVEL": "DEBUG"
},
"args": []
}
},
]
}
72 changes: 72 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-05-01/resources"
"github.com/Azure/go-autorest/autorest"
"github.com/whiteducksoftware/azure-arm-action/pkg/github"
"github.com/whiteducksoftware/azure-arm-action/pkg/github/actions"
)

var (
opts *github.Options
authorizer *autorest.Authorizer
deploymentResult resources.DeploymentExtended
)

func TestLoadOptions(t *testing.T) {
var err error
opts, err = github.LoadOptions()
if err != nil {
t.Error(err.Error())
}
}

func TestAuthentication(t *testing.T) {
var err error
authorizer, err = actions.Authenticate(opts.Inputs)
if err != nil {
t.Error(err.Error())
}
}

func TestDeploy(t *testing.T) {
var err error
deploymentResult, err = actions.Deploy(context.Background(), opts.Inputs, authorizer)
if err != nil {
t.Error(err.Error())
}
}

func TestParseOutputs(t *testing.T) {
outputs, err := actions.ParseOutputs(deploymentResult.Properties.Outputs)
if err != nil {
t.Error(err.Error())
}

if len(outputs) != 2 {
t.Errorf("Got invalid count of outputs, expected 2 got %d", len(outputs))
}

// Test output key location
value, ok := outputs["location"]
if !ok {
t.Errorf("Test key is missing in the outputs, exptected the key location to be present")
}

if value.Value != "westeurope" {
t.Errorf("Got invalid value for location key, expected %s got %s", "westeurope", value.Value)
}

// Test output key containername
value, ok = outputs["containerName"]
if !ok {
t.Errorf("Test key is missing in the outputs, exptected the key containerName to be present")
}

if value.Value != "github-action" {
t.Errorf("Got invalid value for location key, expected %s got %s", "github-action", value.Value)
}
}
8 changes: 4 additions & 4 deletions test/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
}
],
"outputs": {
"resourceID": {
"location": {
"type": "string",
"value": "[resourceId('Microsoft.ContainerInstance/containerGroups', parameters('containerName'))]"
"value": "[parameters('location')]"
},
"resourceID2": {
"containerName": {
"type": "string",
"value": "[resourceId('Microsoft.ContainerInstance/containerGroups', parameters('containerName'))]"
"value": "[parameters('containerName')]"
}
}
}

0 comments on commit a236fc5

Please sign in to comment.