Skip to content

Commit

Permalink
Merge pull request #1 from kehoecj/main
Browse files Browse the repository at this point in the history
Add Go Pipeline
  • Loading branch information
kehoecj authored Dec 15, 2022
2 parents 9b8099d + b39716a commit b83d112
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 37 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on: push

jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Static Analysis
run: go vet ./...

- name: Check Formatting
run: if [ "$(gofmt -s -l -e . | wc -l)" -gt 0 ]; then exit 1; fi

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags='-w -s -extldflags "-static"' -tags netgo -o validator cmd/validator/validator.go

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Test
run: go test -v ./...


2 changes: 1 addition & 1 deletion cmd/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"flag"
"git.web.boeing.com/vle-oss/config-file-validator/pkg/cli"
"github.com/Boeing/config-file-validator/pkg/cli"
"log"
"os"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module git.web.boeing.com/vle-oss/config-file-validator
module github.com/Boeing/config-file-validator

go 1.18

Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cli

import (
"git.web.boeing.com/vle-oss/config-file-validator/pkg/filetype"
"git.web.boeing.com/vle-oss/config-file-validator/pkg/finder"
"git.web.boeing.com/vle-oss/config-file-validator/pkg/reporter"
"io/ioutil"
"fmt"
"github.com/Boeing/config-file-validator/pkg/filetype"
"github.com/Boeing/config-file-validator/pkg/finder"
"github.com/Boeing/config-file-validator/pkg/reporter"
"io/ioutil"
)

type CLI struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/filetype/file_type.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package filetype

import (
"git.web.boeing.com/vle-oss/config-file-validator/pkg/validator"
"github.com/Boeing/config-file-validator/pkg/validator"
)

// The FileType object stores information
Expand Down
2 changes: 1 addition & 1 deletion pkg/finder/finder.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package finder

import (
"git.web.boeing.com/vle-oss/config-file-validator/pkg/filetype"
"github.com/Boeing/config-file-validator/pkg/filetype"
)

// The File Metadata object stores the
Expand Down
2 changes: 1 addition & 1 deletion pkg/finder/finder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package finder

import (
"git.web.boeing.com/vle-oss/config-file-validator/pkg/filetype"
"github.com/Boeing/config-file-validator/pkg/filetype"
"testing"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/finder/fsfinder.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package finder

import (
"git.web.boeing.com/vle-oss/config-file-validator/pkg/filetype"
"github.com/Boeing/config-file-validator/pkg/filetype"
"io/fs"
"os"
"path/filepath"
Expand Down
7 changes: 3 additions & 4 deletions pkg/validator/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package validator

import (
"encoding/json"
"strings"
"fmt"

"strings"
)

type JsonValidator struct{}

// Returns a custom error message that contains the unmarshal
// Returns a custom error message that contains the unmarshal
// error message along with the line and character
// number where the error occurred when parsing the JSON
func getCustomErr(input []byte, err error) (error) {
func getCustomErr(input []byte, err error) error {
jsonError := err.(*json.SyntaxError)
offset := int(jsonError.Offset)
line := 1 + strings.Count(string(input)[:offset], "\n")
Expand Down
43 changes: 21 additions & 22 deletions pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@ import (
)

var testData = []struct {
name string
testInput []byte
name string
testInput []byte
expectedResult bool
validator Validator
validator Validator
}{
{"validJson", []byte(`{"test": "test"}`), true, JsonValidator{}},
{"invalidJson", []byte(`{test": "test"}`), false, JsonValidator{}},
{"validYaml", []byte("a: 1\nb: 2"), true, YamlValidator{}},
{"invalidYaml", []byte("a: b\nc: d:::::::::::::::"), false, YamlValidator{}},
{"validXml", []byte("<test>\n</test>"), true, XmlValidator{}},
{"invalidXml", []byte("<xml\n"), false, XmlValidator{}},
{"validJson", []byte(`{"test": "test"}`), true, JsonValidator{}},
{"invalidJson", []byte(`{test": "test"}`), false, JsonValidator{}},
{"validYaml", []byte("a: 1\nb: 2"), true, YamlValidator{}},
{"invalidYaml", []byte("a: b\nc: d:::::::::::::::"), false, YamlValidator{}},
{"validXml", []byte("<test>\n</test>"), true, XmlValidator{}},
{"invalidXml", []byte("<xml\n"), false, XmlValidator{}},
}


func Test_ValidationInput(t *testing.T) {
for _, d := range testData {
valid, err := d.validator.Validate(d.testInput)
if valid != d.expectedResult {
t.Errorf("incorrect result: expected %v, got %v", d.expectedResult, valid)
}

if valid && err != nil {
t.Error("incorrect result: err was not nil", err)
}
valid, err := d.validator.Validate(d.testInput)
if valid != d.expectedResult {
t.Errorf("incorrect result: expected %v, got %v", d.expectedResult, valid)
}

if ! valid && err == nil {
t.Error("incorrect result: function returned a nil error")
}
if valid && err != nil {
t.Error("incorrect result: err was not nil", err)
}
}

if !valid && err == nil {
t.Error("incorrect result: function returned a nil error")
}
}
}
2 changes: 1 addition & 1 deletion pkg/validator/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ func (xv XmlValidator) Validate(b []byte) (bool, error) {
return false, err
}
return true, nil
}
}

0 comments on commit b83d112

Please sign in to comment.