Skip to content
/ goju Public

GoJU is a Go JSON Unit Test Library: implementing unit tests for JSON in JSON files

License

Notifications You must be signed in to change notification settings

endocode/goju

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goju

Goju is for Go JSON UNIT tests.

The idea

It is intended to test JSON files using other json files

{
  "items": [ {
               "spec": {
                 "containers": [ {
                                 "image": "k8s.gcr.io/heapster-amd64:v1.5.0"
                                 }
                               ]
               }
             }
           ]
}

is checked for regular expression by the JSON file

{
  "items": {
    "length" :"1",
    "spec":{
      "containers":{
        "image":{
           "matches":"^(gcr.io/(google[-_]containers|k8s-minikube)|k8s.gcr.io)"
        }
      }
    }
  }
}

This means, the items array is checked for length 1 and any images in the items/spec/containers array is checked, if the string matches the regular expression. More examples are in the data directory.

The concept is to check configurations by other configurations, and implement checks adding additional leaves in JSON or YAML.

The executable checks are invoked by reflection on a Check object and must have the same name as define in the check.go file with a leading capital letter.

Installation

Install Goju by

go get github.com/endodoce/goju

Usage

Simply call

goju  -json=data/imagepod.json -rule=data/imagerule.json

to get an output like

I0624 13:24:16.733258    3384 main.go:29] Errors       : 0
I0624 13:24:16.733543    3384 main.go:30] Checks   true: 2
I0624 13:24:16.733573    3384 main.go:31] Checks  false: 0

The errors are parsing errors like unknown functions and the check results, which are true and false are reported

About

GoJU is a Go JSON Unit Test Library: implementing unit tests for JSON in JSON files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages