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

Commit

Permalink
Fixed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
StiviiK committed Jul 8, 2021
1 parent bd95791 commit ed03750
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Unit Tests
on:
pull_request:
push:
branches:
- 'master'

jobs:
test_action_job:
Expand All @@ -24,7 +22,7 @@ jobs:
GOOS: linux
GOARCH: amd64
run: go build -a -installsuffix cgo -ldflags="-w -s" .

- name: Test
env:
GOPROXY: "https://proxy.golang.org"
Expand All @@ -38,6 +36,7 @@ jobs:
INPUT_PARAMETERS: ./test/parameters.json
INPUT_OVERRIDEPARAMETERS: |
containerName=github-action-overriden
connectionString='Server=tcp:test.database.windows.net;Database=test;User ID=test;Password=test;Trusted_Connection=False;Encrypt=True;'
INPUT_DEPLOYMENTNAME: github-test
INPUT_DEPLOYMENTMODE: Incremental
run: go test -v -failfast .
18 changes: 15 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestParseOutputs(t *testing.T) {
t.Error(err.Error())
}

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

// Test output key location
Expand All @@ -68,6 +68,18 @@ func TestParseOutputs(t *testing.T) {

// This also tests if the override did work
if value.Value != "github-action-overriden" {
t.Errorf("Got invalid value for location key, expected %s got %s", "github-action-overriden", value.Value)
t.Errorf("Got invalid value for containerName key, expected %s got %s", "github-action-overriden", value.Value)
}

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

// This also tests if the override did work
var expectedConnectionString = "Server=tcp:test.database.windows.net;Database=test;User ID=test;Password=test;Trusted_Connection=False;Encrypt=True;"
if value.Value != expectedConnectionString {
t.Errorf("Got invalid value for connectionString key, expected %s got %s", expectedConnectionString, value.Value)
}
}
4 changes: 2 additions & 2 deletions pkg/github/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func wrapReadRawParameters(v string) (interface{}, error) {
pairs := strings.FieldsFunc(v, f)

for _, keyValuePair := range pairs {
keyValue := strings.Split(keyValuePair, "=")
keyValue := strings.SplitN(keyValuePair, "=", 2)
if len(keyValue) != 2 {
return nil, fmt.Errorf("Found invalid pair, expected KEY=VALUE got %s", keyValuePair)
}
Expand All @@ -151,7 +151,7 @@ func wrapReadRawParameters(v string) (interface{}, error) {
}, keyValue[1])

parameter[keyValue[0]] = make(map[string]string)
parameter[keyValue[0]].(map[string]string)["value"] = strings.TrimSpace(value)
parameter[keyValue[0]].(map[string]string)["value"] = value
}

return parameter, nil
Expand Down
3 changes: 3 additions & 0 deletions test/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"protocol": "TCP"
}
]
},
"connectionString": {
"value": "not_a_real_connection_string"
}
}
}
7 changes: 7 additions & 0 deletions test/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
},
"ports": {
"type": "array"
},
"connectionString": {
"type": "string"
}
},
"resources": [
Expand Down Expand Up @@ -86,6 +89,10 @@
"containerName": {
"type": "string",
"value": "[parameters('containerName')]"
},
"connectionString": {
"type": "string",
"value": "[parameters('connectionString')]"
}
}
}

0 comments on commit ed03750

Please sign in to comment.