Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c391939960 | ||
|
|
340c90211f | ||
|
|
e737280a3c | ||
|
|
18d1d2730f | ||
|
|
fc1f3fa814 | ||
|
|
3151405d32 | ||
|
|
154c9f493e |
@@ -2,45 +2,43 @@ name: Go
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, go_migr ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main, go_migr ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-24.04 # You can change this to macos-latest or windows-latest if needed
|
runs-on: ubuntu-24.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version: '1.24.6' # You can specify a specific version or 'stable'
|
go-version: '1.26.1'
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
go build -v -ldflags "\
|
echo "Initializing config"
|
||||||
-X main.version=${{ github.ref_name }} \
|
mkdir -p ~/.ssh
|
||||||
-X main.commit=${{ github.sha }} \
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
||||||
-X main.date=$(date +%Y-%m-%dT%H:%M:%S%z)" \
|
chmod 600 ~/.ssh/textsender_models_deploy_key
|
||||||
-o clean_file
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
||||||
|
|
||||||
|
go env -w GOPRIVATE='${{ secrets.GIT_HOST_ROOT }}'
|
||||||
|
|
||||||
|
echo "Creating local .gitconfig"
|
||||||
|
touch ~/.gitconfig
|
||||||
|
cat > ~/.gitconfig << "EOF"
|
||||||
|
[url "ssh://git@${{ secrets.GIT_HOST_ROOT }}"]
|
||||||
|
insteadOf = https://${{ secrets.GIT_HOST_ROOT }}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
make build
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test -v ./...
|
run: go test -v ./...
|
||||||
|
|
||||||
- name: Run gofmt (optional)
|
|
||||||
# Uncomment to check code formatting with gofmt
|
|
||||||
run: |
|
|
||||||
if [ -n "$(gofmt -l.)" ]; then
|
|
||||||
echo "Go code is not formatted. Please run 'gofmt -w.' to fix it."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Run golint (optional)
|
|
||||||
# Uncomment to check code style with golint
|
|
||||||
run: |
|
|
||||||
if [ -n "$(golint./...)" ]; then
|
|
||||||
echo "Go code has style issues. Please run 'golint./...' to see them."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
|
/vendor
|
||||||
/clean_file
|
/clean_file
|
||||||
numbers.json
|
numbers.json
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
stages:
|
|
||||||
- build
|
|
||||||
- test
|
|
||||||
|
|
||||||
build:
|
|
||||||
stage: build
|
|
||||||
image: rust:1.85
|
|
||||||
script:
|
|
||||||
- cargo build --release
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- target/release/clean_file
|
|
||||||
expire_in: 1 week
|
|
||||||
cache:
|
|
||||||
key: "cargo-cache"
|
|
||||||
paths:
|
|
||||||
- target/
|
|
||||||
- ~/.cargo/
|
|
||||||
|
|
||||||
test:
|
|
||||||
stage: test
|
|
||||||
image: rust:1.85
|
|
||||||
script:
|
|
||||||
- cargo test
|
|
||||||
cache:
|
|
||||||
key: "cargo-cache"
|
|
||||||
paths:
|
|
||||||
- target/
|
|
||||||
- ~/.cargo/
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
VERSION ?= $(shell git describe --tags 2>/dev/null || echo "dev")
|
||||||
|
COMMIT ?= $(shell git rev-parse --short HEAD)
|
||||||
|
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
GO_VERSION ?= $(shell go version | awk '{print $$3}')
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
|
go build -ldflags="\
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.Version=$(VERSION)' \
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.BuildTime=$(BUILD_TIME)' \
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.Commit=$(COMMIT)' \
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.GoVersion=$(GO_VERSION)'" \
|
||||||
|
-o clean_file cmd/clean_file/main.go
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install:
|
||||||
|
go install -ldflags="\
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.Version=$(VERSION)' \
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.BuildTime=$(BUILD_TIME)' \
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.Commit=$(COMMIT)' \
|
||||||
|
-X 'git.kundeng.us/phoenix/clean_file/internal/version.GoVersion=$(GO_VERSION)'"
|
||||||
|
-o clean_file cmd/clean_file/main.go
|
||||||
@@ -2,12 +2,7 @@ CLI software that processes a text file containing US phone numbers
|
|||||||
and sanitizes the numbers. The result is contained in a json file.
|
and sanitizes the numbers. The result is contained in a json file.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
```
|
|
||||||
go build
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
To include version information
|
|
||||||
```
|
```
|
||||||
go build -ldflags "-X main.version=3.0.101 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date +%Y-%m-%dT%H:%M:%S%z)" -o clean_file
|
make build
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/clean_file/internal/parser"
|
||||||
|
"git.kundeng.us/phoenix/clean_file/internal/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
args := os.Args
|
||||||
|
|
||||||
|
if len(args) < 2 {
|
||||||
|
log.Println("Invalid arguments provided")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
versionFlag := flag.Bool("version", false, "Print version information")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *versionFlag {
|
||||||
|
fmt.Println(version.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("clean_file")
|
||||||
|
filepath := args[1]
|
||||||
|
|
||||||
|
log.Println("File path:", filepath)
|
||||||
|
prsr := parser.NumberParser{FilePath: filepath}
|
||||||
|
|
||||||
|
numbers := prsr.FileDump()
|
||||||
|
prsr.PrintValues(numbers, true)
|
||||||
|
|
||||||
|
prsr.SaveFile(numbers)
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
module git.kundeng.us/phoenix/clean_file
|
module git.kundeng.us/phoenix/clean_file
|
||||||
|
|
||||||
go 1.25.3
|
go 1.26.1
|
||||||
|
|
||||||
|
require git.kundeng.us/phoenix/textsender-models v0.2.0
|
||||||
|
|
||||||
|
require github.com/google/uuid v1.6.0 // indirect
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
git.kundeng.us/phoenix/textsender-models v0.2.0 h1:smz8Fs8VOs1Ya23txbOM0YPRidZIsM0yE9unHF0D/nQ=
|
||||||
|
git.kundeng.us/phoenix/textsender-models v0.2.0/go.mod h1:3CkqA/HFKPhpMYxkKn5uVbZEzEbG3sofLZE8pZ1BHO4=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
@@ -1,110 +1,106 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
import "os"
|
|
||||||
import "unicode"
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
)
|
)
|
||||||
import "encoding/json"
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
const Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
type SomeObject struct {
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NumberParser struct {
|
type NumberParser struct {
|
||||||
FilePath string
|
FilePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prsr NumberParser) FileDump() []SomeObject {
|
func (prsr *NumberParser) FileDump() []contact.Contact {
|
||||||
fmt.Println("Dumping files")
|
log.Println("Dumping files")
|
||||||
objs := []SomeObject{}
|
objs := []contact.Contact{}
|
||||||
|
|
||||||
for _, line := range prsr.readLines(prsr.FilePath) {
|
for _, line := range prsr.readLines(prsr.FilePath) {
|
||||||
if strings.ContainsAny(line, Letters) {
|
if strings.ContainsAny(line, Letters) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
myObj := SomeObject{Value: line}
|
myObj := contact.Contact{PhoneNumber: line}
|
||||||
if myObj.Value != "" {
|
if myObj.PhoneNumber != "" {
|
||||||
objs = append(objs, myObj)
|
objs = append(objs, myObj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
objs = prsr.updateContacts(objs)
|
||||||
|
objs = prsr.removeDups(objs)
|
||||||
|
|
||||||
return objs
|
return objs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prsr NumberParser) UpdateValues(vals []SomeObject) []SomeObject {
|
func (prsr *NumberParser) updateContacts(contacts []contact.Contact) []contact.Contact {
|
||||||
updated := []SomeObject{}
|
updated := []contact.Contact{}
|
||||||
|
|
||||||
for _, val := range vals {
|
for _, ct := range contacts {
|
||||||
parsed := val.Value
|
parsed := ct.PhoneNumber
|
||||||
if len(parsed) < 2 {
|
if len(parsed) < 2 {
|
||||||
fmt.Println("Invalid number:", parsed)
|
log.Println("Invalid number:", parsed)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pars := prsr.removeSomeData(parsed)
|
pars := prsr.removeSomeData(parsed)
|
||||||
parsed = pars
|
parsed = pars
|
||||||
|
|
||||||
fmt.Println(parsed)
|
log.Println("Parsed:", parsed)
|
||||||
|
|
||||||
updatedParsed := prsr.addPrefix(parsed)
|
updatedParsed := prsr.addPrefix(parsed)
|
||||||
updated = append(updated, SomeObject{Value: updatedParsed})
|
updated = append(updated, contact.Contact{PhoneNumber: updatedParsed})
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prsr NumberParser) RemoveDups(vals []SomeObject) []SomeObject {
|
func (prsr *NumberParser) removeDups(contacts []contact.Contact) []contact.Contact {
|
||||||
updated := []SomeObject{}
|
updated := []contact.Contact{}
|
||||||
uniqueItems := make(map[string]string)
|
uniqueItems := make(map[string]string)
|
||||||
|
|
||||||
for _, val := range vals {
|
for _, val := range contacts {
|
||||||
uniqueItems[val.Value] = val.Value
|
uniqueItems[val.PhoneNumber] = val.PhoneNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range uniqueItems {
|
for _, item := range uniqueItems {
|
||||||
updated = append(updated, SomeObject{Value: item})
|
updated = append(updated, contact.Contact{PhoneNumber: item})
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prsr NumberParser) PrintValues(vals []SomeObject, printTotal bool) {
|
func (prsr NumberParser) PrintValues(contacts []contact.Contact, printTotal bool) {
|
||||||
fmt.Println("Printing values")
|
fmt.Println("Printing numbers")
|
||||||
|
|
||||||
for _, val := range vals {
|
for _, ct := range contacts {
|
||||||
fmt.Println("Value:", val.Value)
|
fmt.Println("Number:", ct.PhoneNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
if printTotal {
|
if printTotal {
|
||||||
fmt.Println("Total Numbers:", len(vals))
|
fmt.Println("Total Numbers:", len(contacts))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prsr NumberParser) SaveFile(vals []SomeObject) {
|
func (prsr NumberParser) SaveFile(vals []contact.Contact) {
|
||||||
filename := "numbers.json"
|
filename := "numbers.json"
|
||||||
allNumbers := []string{}
|
|
||||||
|
|
||||||
for _, val := range vals {
|
|
||||||
allNumbers = append(allNumbers, val.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create json and save it to the filesystem
|
// Create json and save it to the filesystem
|
||||||
jsonData, err := json.MarshalIndent(allNumbers, "", " ")
|
jsonData, err := json.MarshalIndent(&vals, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error marshaling JSON:", err)
|
log.Println("Error marshaling JSON:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.WriteFile(filename, jsonData, 0644)
|
err = os.WriteFile(filename, jsonData, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error writing file:", err)
|
log.Println("Error writing file:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +144,7 @@ func (prsr NumberParser) removeSomeData(unparsed string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Parsed:", parsed)
|
log.Println("Parsed:", parsed)
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Test_File_Path = "../../tests/numbers.txt"
|
||||||
|
|
||||||
|
// Remove duplicates
|
||||||
|
func Test_RemoveDups(t *testing.T) {
|
||||||
|
parser := NumberParser{FilePath: Test_File_Path}
|
||||||
|
finalAmount := parser.FileDump()
|
||||||
|
|
||||||
|
if len(finalAmount) < 1 {
|
||||||
|
t.Error("Dump should not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
testValues := []contact.Contact{
|
||||||
|
{PhoneNumber: "+12175550194"},
|
||||||
|
{PhoneNumber: "+16025550177"},
|
||||||
|
{PhoneNumber: "+17135550167"},
|
||||||
|
{PhoneNumber: "+16085550190"},
|
||||||
|
{PhoneNumber: "+13055550112"},
|
||||||
|
{PhoneNumber: "+14155550135"},
|
||||||
|
{PhoneNumber: "+13175550123"},
|
||||||
|
{PhoneNumber: "+13605550158"},
|
||||||
|
}
|
||||||
|
|
||||||
|
aSize := len(finalAmount)
|
||||||
|
bSize := len(testValues)
|
||||||
|
if aSize != bSize {
|
||||||
|
t.Error("Data has varrying sizes A", aSize, " B", bSize)
|
||||||
|
}
|
||||||
|
if !dataEqual(finalAmount, testValues) {
|
||||||
|
fmt.Println("Printing final amount")
|
||||||
|
for _, val := range finalAmount {
|
||||||
|
fmt.Println("PhoneNumber:", val.PhoneNumber)
|
||||||
|
}
|
||||||
|
fmt.Println("\nPrinting test values")
|
||||||
|
for _, val := range testValues {
|
||||||
|
fmt.Println("PhoneNumber:", val.PhoneNumber)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Error("Data has not been updated")
|
||||||
|
} else {
|
||||||
|
log.Println("The duplicates have been removed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataEqual(a, b []contact.Contact) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range a {
|
||||||
|
foundIt := false
|
||||||
|
for j := range b {
|
||||||
|
if a[i] == b[j] {
|
||||||
|
foundIt = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !foundIt {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var (
|
||||||
|
Version = "dev"
|
||||||
|
BuildTime = "unknown"
|
||||||
|
Commit = "unknown"
|
||||||
|
GoVersion = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
func String() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"Version: %s\nBuild Date: %s\nCommit: %s\nGo Version: %s",
|
||||||
|
Version, BuildTime, Commit, GoVersion,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
import "os"
|
|
||||||
import "git.kundeng.us/phoenix/clean_file/parser"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("clean_file")
|
|
||||||
args := os.Args
|
|
||||||
|
|
||||||
if len(args) < 2 {
|
|
||||||
fmt.Println("Invalid arguments provided")
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
filepath := args[1]
|
|
||||||
|
|
||||||
fmt.Println("File path:", filepath)
|
|
||||||
prsr := parser.NumberParser{FilePath: filepath}
|
|
||||||
|
|
||||||
rawValues := prsr.FileDump()
|
|
||||||
parsedValues := prsr.UpdateValues(rawValues)
|
|
||||||
newUpdated := prsr.RemoveDups(parsedValues)
|
|
||||||
|
|
||||||
prsr.PrintValues(newUpdated, true)
|
|
||||||
|
|
||||||
prsr.SaveFile(newUpdated)
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
package parser
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
const Test_File_Path = "../tests/numbers.txt"
|
|
||||||
|
|
||||||
// Add three tests
|
|
||||||
// File dump
|
|
||||||
func Test_FileDump(t *testing.T) {
|
|
||||||
parser := NumberParser{FilePath: Test_File_Path}
|
|
||||||
rawValues := parser.FileDump()
|
|
||||||
|
|
||||||
testValues := []SomeObject{
|
|
||||||
{Value: "(217) 555-0194"},
|
|
||||||
{Value: "(602) 555-0177"},
|
|
||||||
{Value: "(713) 555-0167"},
|
|
||||||
{Value: "(608) 555-0190"},
|
|
||||||
{Value: "(305) 555-0112"},
|
|
||||||
{Value: "(415) 555-0135"},
|
|
||||||
{Value: "(608) 555-0190"},
|
|
||||||
{Value: "(602) 555-0177"},
|
|
||||||
{Value: "(317) 555-0123"},
|
|
||||||
{Value: "(360) 555-0158"},
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(rawValues) < 1 {
|
|
||||||
t.Error("Dump should not be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !dataEqual(rawValues, testValues) {
|
|
||||||
t.Error("File dump was not correctly dump")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse values
|
|
||||||
func Test_Parsed(t *testing.T) {
|
|
||||||
parser := NumberParser{FilePath: Test_File_Path}
|
|
||||||
rawValues := parser.FileDump()
|
|
||||||
|
|
||||||
if len(rawValues) < 1 {
|
|
||||||
t.Error("Dump should not be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed := parser.UpdateValues(rawValues)
|
|
||||||
testValues := []SomeObject{
|
|
||||||
{Value: "+12175550194"},
|
|
||||||
{Value: "+16025550177"},
|
|
||||||
{Value: "+17135550167"},
|
|
||||||
{Value: "+16085550190"},
|
|
||||||
{Value: "+13055550112"},
|
|
||||||
{Value: "+14155550135"},
|
|
||||||
{Value: "+16085550190"},
|
|
||||||
{Value: "+16025550177"},
|
|
||||||
{Value: "+13175550123"},
|
|
||||||
{Value: "+13605550158"},
|
|
||||||
}
|
|
||||||
|
|
||||||
aSize := len(parsed)
|
|
||||||
bSize := len(testValues)
|
|
||||||
if aSize != bSize {
|
|
||||||
t.Error("Data has varrying sizes A", aSize, " B", bSize)
|
|
||||||
}
|
|
||||||
if !dataEqual(parsed, testValues) {
|
|
||||||
t.Error("Data has not be updated")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove duplicates
|
|
||||||
func Test_RemoveDups(t *testing.T) {
|
|
||||||
parser := NumberParser{FilePath: Test_File_Path}
|
|
||||||
rawValues := parser.FileDump()
|
|
||||||
|
|
||||||
if len(rawValues) < 1 {
|
|
||||||
t.Error("Dump should not be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed := parser.UpdateValues(rawValues)
|
|
||||||
finalAmount := parser.RemoveDups(parsed)
|
|
||||||
testValues := []SomeObject{
|
|
||||||
{Value: "+12175550194"},
|
|
||||||
{Value: "+16025550177"},
|
|
||||||
{Value: "+17135550167"},
|
|
||||||
{Value: "+16085550190"},
|
|
||||||
{Value: "+13055550112"},
|
|
||||||
{Value: "+14155550135"},
|
|
||||||
{Value: "+13175550123"},
|
|
||||||
{Value: "+13605550158"},
|
|
||||||
}
|
|
||||||
|
|
||||||
aSize := len(finalAmount)
|
|
||||||
bSize := len(testValues)
|
|
||||||
if aSize != bSize {
|
|
||||||
t.Error("Data has varrying sizes A", aSize, " B", bSize)
|
|
||||||
}
|
|
||||||
if !dataEqual(finalAmount, testValues) {
|
|
||||||
fmt.Println("Printing final amount")
|
|
||||||
for _, val := range finalAmount {
|
|
||||||
fmt.Println("Value:", val.Value)
|
|
||||||
}
|
|
||||||
fmt.Println("Printing test values")
|
|
||||||
for _, val := range testValues {
|
|
||||||
fmt.Println("Value:", val.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Error("Data has not be updated")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func dataEqual(a, b []SomeObject) bool {
|
|
||||||
if len(a) != len(b) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range a {
|
|
||||||
foundIt := false
|
|
||||||
for j := range b {
|
|
||||||
if a[i] == b[j] {
|
|
||||||
foundIt = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !foundIt {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package version
|
|
||||||
|
|
||||||
var (
|
|
||||||
Version = "dev"
|
|
||||||
Commit = "none"
|
|
||||||
Date = "unknown"
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user