github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/pkg/claimsheader/claimsheader_test.go (about) 1 // +build !windows 2 3 package claimsheader 4 5 import ( 6 "testing" 7 8 . "github.com/smartystreets/goconvey/convey" 9 ) 10 11 func TestHeader(t *testing.T) { 12 13 Convey("Given I create a new claims header", t, func() { 14 header := NewClaimsHeader( 15 OptionEncrypt(true), 16 OptionCompressionType(CompressionTypeV1), 17 OptionDatapathVersion(DatapathVersion1), 18 OptionPing(true), 19 ).ToBytes() 20 21 Convey("Then claims header should not be nil", func() { 22 So(header, ShouldNotBeNil) 23 }) 24 25 Convey("Given I convert bytes to claims header", func() { 26 ch := header.ToClaimsHeader() 27 28 Convey("Then it should be equal", func() { 29 So(ch.CompressionType(), ShouldEqual, CompressionTypeV1) 30 So(ch.Encrypt(), ShouldEqual, true) 31 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 32 So(ch.Ping(), ShouldEqual, true) 33 }) 34 }) 35 }) 36 37 Convey("Given I create a new claims header and encrypt false", t, func() { 38 header := NewClaimsHeader( 39 OptionEncrypt(false), 40 OptionPing(true), 41 OptionCompressionType(CompressionTypeV1), 42 OptionDatapathVersion(DatapathVersion1), 43 ).ToBytes() 44 45 Convey("Then claims header should not be nil", func() { 46 So(header, ShouldNotBeNil) 47 }) 48 49 Convey("Given I convert bytes to claims header", func() { 50 ch := header.ToClaimsHeader() 51 52 Convey("Then it should be equal", func() { 53 So(ch.CompressionType(), ShouldEqual, CompressionTypeV1) 54 So(ch.Encrypt(), ShouldEqual, false) 55 So(ch.Ping(), ShouldEqual, true) 56 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 57 }) 58 }) 59 }) 60 61 Convey("Given I create a new claims header and with no ping", t, func() { 62 header := NewClaimsHeader( 63 OptionEncrypt(false), 64 OptionDatapathVersion(DatapathVersion1), 65 ).ToBytes() 66 67 Convey("Then claims header should not be nil", func() { 68 So(header, ShouldNotBeNil) 69 }) 70 71 Convey("Given I convert bytes to claims header", func() { 72 ch := header.ToClaimsHeader() 73 74 Convey("Then it should be equal", func() { 75 So(ch.CompressionType(), ShouldEqual, CompressionTypeV1) 76 So(ch.Encrypt(), ShouldEqual, false) 77 So(ch.Ping(), ShouldEqual, false) 78 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 79 }) 80 }) 81 }) 82 83 Convey("Given I create a new claims header and encrypt false", t, func() { 84 header := NewClaimsHeader( 85 OptionEncrypt(false), 86 OptionPing(false), 87 OptionCompressionType(CompressionTypeV1), 88 OptionDatapathVersion(DatapathVersion1), 89 ).ToBytes() 90 91 Convey("Then claims header should not be nil", func() { 92 So(header, ShouldNotBeNil) 93 }) 94 95 Convey("Given I convert bytes to claims header", func() { 96 ch := header.ToClaimsHeader() 97 98 Convey("Then it should be equal", func() { 99 So(ch.CompressionType(), ShouldEqual, CompressionTypeV1) 100 So(ch.Encrypt(), ShouldEqual, false) 101 So(ch.Ping(), ShouldEqual, false) 102 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 103 }) 104 }) 105 }) 106 107 Convey("Given I create a new claims header and change it later", t, func() { 108 header := NewClaimsHeader( 109 OptionEncrypt(false), 110 OptionDatapathVersion(DatapathVersion1), 111 OptionPing(false), 112 ) 113 114 Convey("Then claims header should not be nil", func() { 115 So(header, ShouldNotBeNil) 116 }) 117 118 Convey("Given I convert bytes to claims header", func() { 119 ch := header.ToBytes().ToClaimsHeader() 120 121 Convey("Then it should be equal", func() { 122 So(ch.CompressionType(), ShouldEqual, CompressionTypeV1) 123 So(ch.Encrypt(), ShouldEqual, false) 124 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 125 So(ch.Ping(), ShouldEqual, false) 126 }) 127 }) 128 129 Convey("Given I set different compression type and encrypt", func() { 130 header.SetCompressionType(CompressionTypeV1) 131 header.SetEncrypt(true) 132 header.SetPing(true) 133 ch := header.ToBytes().ToClaimsHeader() 134 135 Convey("Then it should be equal", func() { 136 So(ch.CompressionType(), ShouldEqual, CompressionTypeV1) 137 So(ch.Encrypt(), ShouldEqual, true) 138 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 139 So(ch.Ping(), ShouldEqual, true) 140 }) 141 }) 142 }) 143 144 Convey("Given I try retrieve fields without any data", t, func() { 145 ch := &ClaimsHeader{} 146 147 Convey("Then it should be equal", func() { 148 So(ch.CompressionType(), ShouldEqual, 0) 149 So(ch.Encrypt(), ShouldEqual, false) 150 So(ch.DatapathVersion(), ShouldEqual, DatapathVersion1) 151 }) 152 }) 153 }