-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regexp for ECS_CLUSTER value fetching (#9)
* fix regexp for bash userdata Some may use user-data scripts like the following one. Don't capture the quotes with the regexp ``` echo "ECS_CLUSTER=core-dev" >> /etc/ecs/ecs.config ``` * Add tests for `ECS_CLUSTER=xxx` regexp * add github test action Co-authored-by: Angel Manuel Martin Canto <angel.martin@aplazame.com>
- Loading branch information
Showing
3 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
jobs: | ||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
go-version: [1.15.x, 1.16.x, 1.17.x] | ||
platform: [ubuntu-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Test | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package drain | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestECSVariable(t *testing.T) { | ||
var testcases = []struct { | ||
testString string | ||
expectedValue string | ||
expectedError error | ||
}{ | ||
{ | ||
testString: `echo "ECS_CLUSTER=test-ecs-cluster123" >> /etc/ecs/ecs.config`, | ||
expectedValue: "test-ecs-cluster123", | ||
}, | ||
{ | ||
testString: `echo 'ECS_CLUSTER=test-ecs-cluster123' >> /etc/ecs/ecs.config`, | ||
expectedValue: "test-ecs-cluster123", | ||
}, | ||
{ | ||
testString: `echo ECS_CLUSTER=test-ecs-cluster123 >> /etc/ecs/ecs.config`, | ||
expectedValue: "test-ecs-cluster123", | ||
}, | ||
{ | ||
testString: `#!/bin/bash -xe | ||
echo ECS_CLUSTER=test-ecs-cluster123 >> /etc/ecs/ecs.config`, | ||
expectedValue: "test-ecs-cluster123", | ||
}, | ||
{ | ||
testString: ` | ||
write_files: | ||
- path: /etc/ecs/ecs.config | ||
append: true | ||
content: | | ||
ECS_CLUSTER=my-super-ECS-cluster-22abc | ||
ECS_CONTAINER_STOP_TIMEOUT=2m | ||
`, | ||
expectedValue: "my-super-ECS-cluster-22abc", | ||
}, | ||
{ | ||
testString: ` | ||
write_files: | ||
- path: /etc/ecs/ecs.config | ||
append: true | ||
content: | | ||
ECS_CONTAINER_STOP_TIMEOUT=2m | ||
`, | ||
expectedError: ErrMissingECSClusterInUserData, | ||
}, | ||
{ | ||
testString: "", | ||
expectedError: ErrMissingECSClusterInUserData, | ||
}, | ||
{ | ||
testString: ` | ||
pip install awscli | ||
aws configure set default.region ${AWS::Region} | ||
echo ECS_CLUSTER=my-super-ECS-cluster-22abc >> /etc/ecs/ecs.config | ||
`, | ||
expectedValue: "my-super-ECS-cluster-22abc", | ||
}, | ||
} | ||
|
||
for i, tst := range testcases { | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
val, err := parseECSClusterValue(tst.testString) | ||
if err != tst.expectedError { | ||
t.Errorf("Expected %v error, but got %v", tst.expectedError, err) | ||
} | ||
|
||
if val != tst.expectedValue { | ||
t.Errorf("Expected %q value, but got %q", tst.expectedValue, val) | ||
} | ||
}) | ||
} | ||
} |