Skip to content

Commit

Permalink
2 remove rogue commas (#18)
Browse files Browse the repository at this point in the history
* Fixed, need to update ci for how im handling BATS now

* Maybe this will just work? Otherwise I likely have to tell it to actually pull the submodules where bats, bats-support, and bats-assert live

* WIP

* Change clone behavior to retrieve submodules (for BATS)

* Maybe I added the submodules incorrectly?

* Attempting with manual cloning

* WIP

* This ought to work but i dont like it and might undo it later...

* Reminded why I was doing the build explicitly (not in BATS)

* Hopefully this works as its much cleaner than overriding Drones default clone behavior

* WIP

* That didnt work, going back to overriding the drone clone
  • Loading branch information
MattInternet committed Jan 17, 2021
1 parent 2abe2fe commit 6cf5b26
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 28 deletions.
21 changes: 13 additions & 8 deletions .ci/.drone.yml
Expand Up @@ -2,19 +2,24 @@ kind: pipeline
type: kubernetes
name: dug test

clone:
disable: true

steps:
- name: clone
image: alpine/git
commands:
- git clone --recurse-submodules https://github.com/unfrl/dug.git .
- git checkout $DRONE_COMMIT
- git submodule update --recursive --remote

# Note: I setup BATS here using this: https://medium.com/@pimterry/testing-your-shell-scripts-with-bats-abfca9bdc5b9
- name: build and test
image: mcr.microsoft.com/dotnet/sdk:5.0
commands:
- apt update
- apt install bats
# Dont allow bats to do the build, thats a convenience for local development but BATS eats a bunch of the output and can hang.
- dotnet publish -r linux-x64 -c Release -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true --self-contained true -o publish ./cli
- bats cli.tests/bats/run.sh

# - name: BATS test
# image: bats:latest
# commands:
# -
- ./cli.tests/bats/run.sh

# - name: test
# image: docker:20.10-dind
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
@@ -0,0 +1,9 @@
[submodule "cli.tests/bats/libs/bats"]
path = cli.tests/bats/libs/bats
url = https://github.com/sstephenson/bats
[submodule "cli.tests/bats/libs/bats-support"]
path = cli.tests/bats/libs/bats-support
url = https://github.com/ztombol/bats-support
[submodule "cli.tests/bats/libs/bats-assert"]
path = cli.tests/bats/libs/bats-assert
url = https://github.com/ztombol/bats-assert
1 change: 1 addition & 0 deletions cli.tests/bats/libs/bats
Submodule bats added at 036081
1 change: 1 addition & 0 deletions cli.tests/bats/libs/bats-assert
Submodule bats-assert added at 9f88b4
1 change: 1 addition & 0 deletions cli.tests/bats/libs/bats-support
Submodule bats-support added at 004e70
54 changes: 35 additions & 19 deletions cli.tests/bats/run.sh 100644 → 100755
@@ -1,6 +1,10 @@
#!/bin/bash
#!./cli.tests/bats/libs/bats/bin/bats
# This test is designed for BATS. Ideally it should be able to be run from the root. If no build of dug is available it will build it then test it.
set -e

load 'libs/bats-support/load'
load 'libs/bats-assert/load'

# This is intended to be run from the root directory with `bats ./cli.tests/bats/run.sh`
# The publish command below is not used in CI/CD, its just there for running bats locally.
setup() {
Expand All @@ -15,54 +19,66 @@ setup() {
EXIT
fi
}
@test "Verify that csv output doesnt have extra commas when using convenience template items like citycountryname and citycountrycontinentname" {
run $DUG google.com --server-count 10 --output-format CSV --output-template ipaddress,citycountryname,citycountrycontinentname
assert_success

for i in "${lines[@]}"
do
:
line_comma_count=$(echo $i | grep -o ',' | wc -l)
assert_equal $line_comma_count 2
done
}

@test "Invoke 'dug version'" {
run $DUG version
[ "$status" -eq 0 ]
[ "$output" = "0.0.1" ]
assert_success
assert_output "0.0.1" #The testing build should always be version 0.0.1
}

@test "Invoking dug without a Hostname should fail" {
run $DUG
[ "$status" -eq 1 ]
[ "$output" = "A Hostname must be provided. (run dug help or dug --help for more info)" ]
assert_failure
assert_line --index 0 "A Hostname must be provided. (run dug help or dug --help for more info)"
}

@test "Invoking dug with --output-format but without --output-template should fail" {
run $DUG --output-format JSON google.com
[ "$status" -eq 1 ]
[[ "$output" == *"Error setting value to option 'output-format':"* ]]
assert_failure
assert_line --index 0 --partial "Error setting value to option 'output-format':"
}

@test "Invoking dug with invalid value in --continents should fail" {
run $DUG --continents AZ,AS,NA google.com
[ "$status" -eq 1 ]
[[ "$output" == *"Error setting value to option 'continents':"* ]]
assert_failure
assert_line --index 0 --partial "Error setting value to option 'continents':"
}

@test "Invoking dug with -v should enable verbose output" {
run $DUG google.com -s 8.8.8.8 -v
[ "$status" -eq 0 ]
[[ "$output" == *"Verbose Output Enabled"* ]]
assert_success
assert_line --index 0 --partial "Verbose Output Enabled"
}

@test "Verify that the default run prints a table with A records" {
run $DUG google.com -s 8.8.8.8
[ "$status" -eq 0 ]
assert_success
# echo "ouput: $output"
[[ "$output" =~ "A records for google.com" ]]
assert_line --index 1 --partial "A records for google.com"
}

@test "Verify that requesting specific records prints the correct table" {
run $DUG google.com -s 8.8.8.8 -q A,MX
[ "$status" -eq 0 ]
assert_success
# echo "ouput: $output"
[[ "$output" =~ "A,MX records for google.com" ]]
assert_line --index 1 --partial "A,MX records for google.com"
}

@test "Verify that requesting specific records, in any case, prints the correct table" {
@test "Verify that requesting specific records, provided in any casing, prints the correct table" {
run $DUG google.com -s 8.8.8.8 -q A,mx,Ns
[ "$status" -eq 0 ]
assert_success
# echo "ouput: $output"
[[ "$output" =~ "A,MX,NS records for google.com" ]]
}
assert_line --index 1 --partial "A,MX,NS records for google.com"
}

2 changes: 1 addition & 1 deletion cli/Services/ConsoleTemplateService.cs
Expand Up @@ -76,7 +76,7 @@ private void DrawCsvResults(Dictionary<DnsServer, List<DnsResponse>> results, Ru
}
try{
string dataString = TemplateHelper.ResponseGetterMap[header](KeyValuePair.Create(server, response)).ToString();
dataString = dataString.Replace(Environment.NewLine, "\\n"); //Cant have real newlines in the csv output...
dataString = dataString.Replace(Environment.NewLine, "\\n").Replace(",",string.Empty); //Cant have real newlines or rogue commas in the csv output...
responseResults.Add(dataString);
}
catch{
Expand Down

0 comments on commit 6cf5b26

Please sign in to comment.