@@ -54,56 +54,63 @@ var _ = Describe("Pyxis Client Instantiation", func() {
5454
5555var _ = Describe ("Policy Resolution" , func () {
5656 Context ("When determining container policy exceptions" , func () {
57- var fakePC * FakePyxisClient
58- BeforeEach (func () {
59- // reset the fake pyxis client before each execution
60- // as a precaution.
61- fakePC = & FakePyxisClient {
62- findImagesByDigestFunc : fidbFuncNoop ,
63- getProjectsFunc : gpFuncNoop ,
64- submitResultsFunc : srFuncNoop ,
57+ It ("should return a scratch policy exception if the project has type flag" , func () {
58+ certProject := & pyxis.CertProject {
59+ Container : pyxis.Container {
60+ Type : "scratch" ,
61+ },
6562 }
66- })
67-
68- It ("should throw an error if unable to get the project from the API" , func () {
69- fakePC .getProjectsFunc = gpFuncReturnError
70- _ , err := GetContainerPolicyExceptions (context .TODO (), fakePC )
71- Expect (err ).To (HaveOccurred ())
72- })
73-
74- It ("should return a scratch policy exception if the project has type flag in the API" , func () {
75- fakePC .getProjectsFunc = gpFuncReturnScratchException
76- p , err := GetContainerPolicyExceptions (context .TODO (), fakePC )
63+ p := GetContainerPolicyExceptions (certProject )
7764 Expect (p ).To (Equal (policy .PolicyScratchNonRoot ))
78- Expect (err ).ToNot (HaveOccurred ())
7965 })
8066
81- It ("should return a scratch policy exception if the project has os_content_type flag in the API" , func () {
82- fakePC .getProjectsFunc = gpFuncReturnScratchImageException
83- p , err := GetContainerPolicyExceptions (context .TODO (), fakePC )
67+ It ("should return a scratch policy exception if the project has os_content_type flag" , func () {
68+ certProject := & pyxis.CertProject {
69+ Container : pyxis.Container {
70+ OsContentType : "Scratch Image" ,
71+ },
72+ }
73+ p := GetContainerPolicyExceptions (certProject )
8474 Expect (p ).To (Equal (policy .PolicyScratchNonRoot ))
85- Expect (err ).ToNot (HaveOccurred ())
8675 })
8776
88- It ("should return a root policy exception if the project has the flag in the API" , func () {
89- fakePC .getProjectsFunc = gpFuncReturnRootException
90- p , err := GetContainerPolicyExceptions (context .TODO (), fakePC )
77+ It ("should return a root policy exception if the project has the flag" , func () {
78+ certProject := & pyxis.CertProject {
79+ Container : pyxis.Container {
80+ DockerConfigJSON : "" ,
81+ Privileged : true ,
82+ },
83+ }
84+ p := GetContainerPolicyExceptions (certProject )
9185 Expect (p ).To (Equal (policy .PolicyRoot ))
92- Expect (err ).ToNot (HaveOccurred ())
9386 })
9487
95- It ("should return a scratch plus root policy exception if the project has the flag in the API" , func () {
96- fakePC .getProjectsFunc = gpFuncReturnScratchRootException
97- p , err := GetContainerPolicyExceptions (context .TODO (), fakePC )
88+ It ("should return a scratch plus root policy exception if the project has the flag" , func () {
89+ certProject := & pyxis.CertProject {
90+ Container : pyxis.Container {
91+ DockerConfigJSON : "" ,
92+ OsContentType : "Scratch Image" ,
93+ Privileged : true ,
94+ },
95+ }
96+ p := GetContainerPolicyExceptions (certProject )
9897 Expect (p ).To (Equal (policy .PolicyScratchRoot ))
99- Expect (err ).ToNot (HaveOccurred ())
10098 })
10199
102- It ("should return a container policy exception if the project no exceptions in the API" , func () {
103- fakePC .getProjectsFunc = gpFuncReturnNoException
104- p , err := GetContainerPolicyExceptions (context .TODO (), fakePC )
100+ It ("should return a container policy exception if the project has no exceptions" , func () {
101+ certProject := & pyxis.CertProject {
102+ Container : pyxis.Container {
103+ Type : "" ,
104+ Privileged : false ,
105+ },
106+ }
107+ p := GetContainerPolicyExceptions (certProject )
108+ Expect (p ).To (Equal (policy .PolicyContainer ))
109+ })
110+
111+ It ("should return a container policy exception if called with nil container project" , func () {
112+ p := GetContainerPolicyExceptions (nil )
105113 Expect (p ).To (Equal (policy .PolicyContainer ))
106- Expect (err ).ToNot (HaveOccurred ())
107114 })
108115 })
109116})
0 commit comments