Skip to content

Commit

Permalink
more tags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrichardsmith committed Sep 6, 2018
1 parent b55294c commit 13ff164
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestAdmit(t *testing.T) {
}
}

func Test(t *testing.T) {
func TestLoadSentry(t *testing.T) {
c := Config{}
s := c.LoadSentry()
if !reflect.DeepEqual(s, ExampleSentry{}) {
Expand Down
16 changes: 16 additions & 0 deletions tags/podtest.json.initlatesttag
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"apiVersion": "v1",
"kind": "Pod",
"spec": {
"containers": [
{
"image": "testimage:pass"
}
],
"initContainers": [
{
"image": "testimage:latest"
}
]
}
}
16 changes: 16 additions & 0 deletions tags/podtest.json.initnotag
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"apiVersion": "v1",
"kind": "Pod",
"spec": {
"containers": [
{
"image": "testimage:pass"
}
],
"initContainers": [
{
"image": "testimage"
}
]
}
}
33 changes: 30 additions & 3 deletions tags/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
)

var (
podnotag []byte
podlatesttag []byte
podpass []byte
podnotag []byte
podlatesttag []byte
podinitnotag []byte
podinitlatesttag []byte
podpass []byte
)

func init() {
Expand All @@ -30,6 +32,14 @@ func init() {
if err != nil {
log.Fatal(err)
}
podinitnotag, err = ioutil.ReadFile("podtest.json.initnotag")
if err != nil {
log.Fatal(err)
}
podinitlatesttag, err = ioutil.ReadFile("podtest.json.initlatesttag")
if err != nil {
log.Fatal(err)
}
}

func TestType(t *testing.T) {
Expand Down Expand Up @@ -58,14 +68,31 @@ func TestAdmit(t *testing.T) {
if resp.Allowed {
t.Fatal("Expected no tag to fail")
}
ar.Request.Object.Raw = podinitnotag
resp = is.Admit(ar)
if resp.Allowed {
t.Fatal("Expected init no tag to fail")
}
ar.Request.Object.Raw = podlatesttag
resp = is.Admit(ar)
if resp.Allowed {
t.Fatal("Expected latest tag to fail")
}
ar.Request.Object.Raw = podinitlatesttag
resp = is.Admit(ar)
if resp.Allowed {
t.Fatal("Expected init latest tag to fail")
}
ar.Request.Object.Raw = podpass[0:5]
resp = is.Admit(ar)
if !strings.Contains(resp.Result.Message, "json parse error") {
t.Fatal("Expecting json parse error")
}
}

func TestName(t *testing.T) {
c := Config{}
if c.Name() != "tags" {
t.Fatal("Failed name test")
}
}

0 comments on commit 13ff164

Please sign in to comment.