How to use isNil method of assertions Package

Best Venom code snippet using assertions.isNil

firstboot_test.go

Source:firstboot_test.go Github

copy

Full Screen

1// -*- Mode: Go; indent-tabs-mode: t -*-2/*3 * Copyright (C) 2015 Canonical Ltd4 *5 * This program is free software: you can redistribute it and/or modify6 * it under the terms of the GNU General Public License version 3 as7 * published by the Free Software Foundation.8 *9 * This program is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with this program. If not, see <http://www.gnu.org/licenses/>.16 *17 */18package devicestate_test19import (20 "fmt"21 "io/ioutil"22 "os"23 "path/filepath"24 "strconv"25 "time"26 . "gopkg.in/check.v1"27 "github.com/snapcore/snapd/asserts"28 "github.com/snapcore/snapd/asserts/assertstest"29 "github.com/snapcore/snapd/asserts/sysdb"30 "github.com/snapcore/snapd/dirs"31 "github.com/snapcore/snapd/osutil"32 "github.com/snapcore/snapd/overlord"33 "github.com/snapcore/snapd/overlord/assertstate"34 "github.com/snapcore/snapd/overlord/auth"35 "github.com/snapcore/snapd/overlord/devicestate"36 "github.com/snapcore/snapd/overlord/snapstate"37 "github.com/snapcore/snapd/overlord/state"38 "github.com/snapcore/snapd/snap"39 "github.com/snapcore/snapd/snap/snaptest"40 "github.com/snapcore/snapd/testutil"41)42type FirstBootTestSuite struct {43 systemctl *testutil.MockCmd44 mockUdevAdm *testutil.MockCmd45 storeSigning *assertstest.StoreStack46 restore func()47 brandPrivKey asserts.PrivateKey48 brandSigning *assertstest.SigningDB49 overlord *overlord.Overlord50}51var _ = Suite(&FirstBootTestSuite{})52func (s *FirstBootTestSuite) SetUpTest(c *C) {53 tempdir := c.MkDir()54 dirs.SetRootDir(tempdir)55 // mock the world!56 err := os.MkdirAll(filepath.Join(dirs.SnapSeedDir, "snaps"), 0755)57 c.Assert(err, IsNil)58 err = os.MkdirAll(filepath.Join(dirs.SnapSeedDir, "assertions"), 0755)59 c.Assert(err, IsNil)60 err = os.MkdirAll(dirs.SnapServicesDir, 0755)61 c.Assert(err, IsNil)62 os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")63 s.systemctl = testutil.MockCommand(c, "systemctl", "")64 s.mockUdevAdm = testutil.MockCommand(c, "udevadm", "")65 err = ioutil.WriteFile(filepath.Join(dirs.SnapSeedDir, "seed.yaml"), nil, 0644)66 c.Assert(err, IsNil)67 rootPrivKey, _ := assertstest.GenerateKey(1024)68 storePrivKey, _ := assertstest.GenerateKey(752)69 s.storeSigning = assertstest.NewStoreStack("can0nical", rootPrivKey, storePrivKey)70 s.restore = sysdb.InjectTrusted(s.storeSigning.Trusted)71 s.brandPrivKey, _ = assertstest.GenerateKey(752)72 s.brandSigning = assertstest.NewSigningDB("my-brand", s.brandPrivKey)73 ovld, err := overlord.New()74 c.Assert(err, IsNil)75 s.overlord = ovld76}77func (s *FirstBootTestSuite) TearDownTest(c *C) {78 dirs.SetRootDir("/")79 os.Unsetenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS")80 s.systemctl.Restore()81 s.mockUdevAdm.Restore()82 s.restore()83}84func (s *FirstBootTestSuite) TestPopulateFromSeedErrorsOnState(c *C) {85 st := s.overlord.State()86 st.Lock()87 defer st.Unlock()88 st.Set("seeded", true)89 _, err := devicestate.PopulateStateFromSeedImpl(st)90 c.Assert(err, ErrorMatches, "cannot populate state: already seeded")91}92func (s *FirstBootTestSuite) TestPopulateFromSeedHappy(c *C) {93 // put a firstboot snap into the SnapBlobDir94 snapYaml := `name: foo95version: 1.0`96 mockSnapFile := snaptest.MakeTestSnapWithFiles(c, snapYaml, nil)97 targetSnapFile := filepath.Join(dirs.SnapSeedDir, "snaps", filepath.Base(mockSnapFile))98 err := os.Rename(mockSnapFile, targetSnapFile)99 c.Assert(err, IsNil)100 // put a firstboot local snap into the SnapBlobDir101 snapYaml = `name: local102version: 1.0`103 mockSnapFile = snaptest.MakeTestSnapWithFiles(c, snapYaml, nil)104 targetSnapFile2 := filepath.Join(dirs.SnapSeedDir, "snaps", filepath.Base(mockSnapFile))105 err = os.Rename(mockSnapFile, targetSnapFile2)106 c.Assert(err, IsNil)107 devAcct := assertstest.NewAccount(s.storeSigning, "developer", map[string]interface{}{108 "account-id": "developerid",109 }, "")110 devAcctFn := filepath.Join(dirs.SnapSeedDir, "assertions", "developer.account")111 err = ioutil.WriteFile(devAcctFn, asserts.Encode(devAcct), 0644)112 c.Assert(err, IsNil)113 snapDecl, err := s.storeSigning.Sign(asserts.SnapDeclarationType, map[string]interface{}{114 "series": "16",115 "snap-id": "snapidsnapid",116 "publisher-id": "developerid",117 "snap-name": "foo",118 "timestamp": time.Now().UTC().Format(time.RFC3339),119 }, nil, "")120 c.Assert(err, IsNil)121 declFn := filepath.Join(dirs.SnapSeedDir, "assertions", "foo.snap-declaration")122 err = ioutil.WriteFile(declFn, asserts.Encode(snapDecl), 0644)123 c.Assert(err, IsNil)124 sha3_384, size, err := asserts.SnapFileSHA3_384(targetSnapFile)125 c.Assert(err, IsNil)126 snapRev, err := s.storeSigning.Sign(asserts.SnapRevisionType, map[string]interface{}{127 "snap-sha3-384": sha3_384,128 "snap-size": fmt.Sprintf("%d", size),129 "snap-id": "snapidsnapid",130 "developer-id": "developerid",131 "snap-revision": "128",132 "timestamp": time.Now().UTC().Format(time.RFC3339),133 }, nil, "")134 c.Assert(err, IsNil)135 revFn := filepath.Join(dirs.SnapSeedDir, "assertions", "foo.snap-revision")136 err = ioutil.WriteFile(revFn, asserts.Encode(snapRev), 0644)137 c.Assert(err, IsNil)138 // add a model assertion and its chain139 assertsChain := s.makeModelAssertionChain(c, "foo")140 for i, as := range assertsChain {141 fn := filepath.Join(dirs.SnapSeedDir, "assertions", strconv.Itoa(i))142 err := ioutil.WriteFile(fn, asserts.Encode(as), 0644)143 c.Assert(err, IsNil)144 }145 // create a seed.yaml146 content := []byte(fmt.Sprintf(`147snaps:148 - name: foo149 file: %s150 devmode: true151 - name: local152 unasserted: true153 file: %s154`, filepath.Base(targetSnapFile), filepath.Base(targetSnapFile2)))155 err = ioutil.WriteFile(filepath.Join(dirs.SnapSeedDir, "seed.yaml"), content, 0644)156 c.Assert(err, IsNil)157 // run the firstboot stuff158 st := s.overlord.State()159 st.Lock()160 defer st.Unlock()161 tsAll, err := devicestate.PopulateStateFromSeedImpl(st)162 c.Assert(err, IsNil)163 // the last task of the last taskset must be mark-seeded164 markSeededTask := tsAll[len(tsAll)-1].Tasks()[0]165 c.Check(markSeededTask.Kind(), Equals, "mark-seeded")166 // and the markSeededTask must wait for the other tasks167 prevTasks := tsAll[len(tsAll)-2].Tasks()168 otherTask := prevTasks[len(prevTasks)-1]169 c.Check(markSeededTask.WaitTasks(), testutil.Contains, otherTask)170 // now run the change and check the result171 chg := st.NewChange("run-it", "run the populate from seed changes")172 for _, ts := range tsAll {173 chg.AddAll(ts)174 }175 c.Assert(st.Changes(), HasLen, 1)176 st.Unlock()177 s.overlord.Settle()178 st.Lock()179 c.Assert(chg.Err(), IsNil)180 // and check the snap got correctly installed181 c.Check(osutil.FileExists(filepath.Join(dirs.SnapMountDir, "foo", "128", "meta", "snap.yaml")), Equals, true)182 c.Check(osutil.FileExists(filepath.Join(dirs.SnapMountDir, "local", "x1", "meta", "snap.yaml")), Equals, true)183 // verify184 r, err := os.Open(dirs.SnapStateFile)185 c.Assert(err, IsNil)186 state, err := state.ReadState(nil, r)187 c.Assert(err, IsNil)188 state.Lock()189 defer state.Unlock()190 // check foo191 info, err := snapstate.CurrentInfo(state, "foo")192 c.Assert(err, IsNil)193 c.Assert(info.SnapID, Equals, "snapidsnapid")194 c.Assert(info.Revision, Equals, snap.R(128))195 pubAcct, err := assertstate.Publisher(st, info.SnapID)196 c.Assert(err, IsNil)197 c.Check(pubAcct.AccountID(), Equals, "developerid")198 var snapst snapstate.SnapState199 err = snapstate.Get(state, "foo", &snapst)200 c.Assert(err, IsNil)201 c.Assert(snapst.DevMode, Equals, true)202 c.Assert(snapst.Required, Equals, true)203 // check local204 info, err = snapstate.CurrentInfo(state, "local")205 c.Assert(err, IsNil)206 c.Assert(info.SnapID, Equals, "")207 c.Assert(info.Revision, Equals, snap.R("x1"))208 var snapst2 snapstate.SnapState209 err = snapstate.Get(state, "local", &snapst2)210 c.Assert(err, IsNil)211 c.Assert(snapst2.Required, Equals, false)212 // and ensure state is now considered seeded213 var seeded bool214 err = state.Get("seeded", &seeded)215 c.Assert(err, IsNil)216 c.Check(seeded, Equals, true)217}218func writeAssertionsToFile(fn string, assertions []asserts.Assertion) {219 multifn := filepath.Join(dirs.SnapSeedDir, "assertions", fn)220 f, err := os.Create(multifn)221 if err != nil {222 panic(err)223 }224 defer f.Close()225 enc := asserts.NewEncoder(f)226 for _, a := range assertions {227 err := enc.Encode(a)228 if err != nil {229 panic(err)230 }231 }232}233func (s *FirstBootTestSuite) TestPopulateFromSeedHappyMultiAssertsFiles(c *C) {234 // put a firstboot snap into the SnapBlobDir235 snapYaml := `name: foo236version: 1.0`237 mockSnapFile := snaptest.MakeTestSnapWithFiles(c, snapYaml, nil)238 fooSnapFile := filepath.Join(dirs.SnapSeedDir, "snaps", filepath.Base(mockSnapFile))239 err := os.Rename(mockSnapFile, fooSnapFile)240 c.Assert(err, IsNil)241 // put a 2nd firstboot snap into the SnapBlobDir242 snapYaml = `name: bar243version: 1.0`244 mockSnapFile = snaptest.MakeTestSnapWithFiles(c, snapYaml, nil)245 barSnapFile := filepath.Join(dirs.SnapSeedDir, "snaps", filepath.Base(mockSnapFile))246 err = os.Rename(mockSnapFile, barSnapFile)247 c.Assert(err, IsNil)248 devAcct := assertstest.NewAccount(s.storeSigning, "developer", map[string]interface{}{249 "account-id": "developerid",250 }, "")251 snapDeclFoo, err := s.storeSigning.Sign(asserts.SnapDeclarationType, map[string]interface{}{252 "series": "16",253 "snap-id": "foosnapidsnapid",254 "publisher-id": "developerid",255 "snap-name": "foo",256 "timestamp": time.Now().UTC().Format(time.RFC3339),257 }, nil, "")258 c.Assert(err, IsNil)259 sha3_384, size, err := asserts.SnapFileSHA3_384(fooSnapFile)260 c.Assert(err, IsNil)261 snapRevFoo, err := s.storeSigning.Sign(asserts.SnapRevisionType, map[string]interface{}{262 "snap-sha3-384": sha3_384,263 "snap-size": fmt.Sprintf("%d", size),264 "snap-id": "foosnapidsnapid",265 "developer-id": "developerid",266 "snap-revision": "128",267 "timestamp": time.Now().UTC().Format(time.RFC3339),268 }, nil, "")269 c.Assert(err, IsNil)270 writeAssertionsToFile("foo.asserts", []asserts.Assertion{devAcct, snapRevFoo, snapDeclFoo})271 snapDeclBar, err := s.storeSigning.Sign(asserts.SnapDeclarationType, map[string]interface{}{272 "series": "16",273 "snap-id": "barsnapidsnapid",274 "publisher-id": "developerid",275 "snap-name": "bar",276 "timestamp": time.Now().UTC().Format(time.RFC3339),277 }, nil, "")278 c.Assert(err, IsNil)279 sha3_384, size, err = asserts.SnapFileSHA3_384(barSnapFile)280 c.Assert(err, IsNil)281 snapRevBar, err := s.storeSigning.Sign(asserts.SnapRevisionType, map[string]interface{}{282 "snap-sha3-384": sha3_384,283 "snap-size": fmt.Sprintf("%d", size),284 "snap-id": "barsnapidsnapid",285 "developer-id": "developerid",286 "snap-revision": "65",287 "timestamp": time.Now().UTC().Format(time.RFC3339),288 }, nil, "")289 c.Assert(err, IsNil)290 writeAssertionsToFile("bar.asserts", []asserts.Assertion{devAcct, snapDeclBar, snapRevBar})291 // add a model assertion and its chain292 assertsChain := s.makeModelAssertionChain(c)293 writeAssertionsToFile("model.asserts", assertsChain)294 // create a seed.yaml295 content := []byte(fmt.Sprintf(`296snaps:297 - name: foo298 file: %s299 - name: bar300 file: %s301`, filepath.Base(fooSnapFile), filepath.Base(barSnapFile)))302 err = ioutil.WriteFile(filepath.Join(dirs.SnapSeedDir, "seed.yaml"), content, 0644)303 c.Assert(err, IsNil)304 // run the firstboot stuff305 st := s.overlord.State()306 st.Lock()307 defer st.Unlock()308 tsAll, err := devicestate.PopulateStateFromSeedImpl(st)309 c.Assert(err, IsNil)310 chg := st.NewChange("run-it", "run the populate from seed changes")311 for _, ts := range tsAll {312 chg.AddAll(ts)313 }314 c.Assert(st.Changes(), HasLen, 1)315 st.Unlock()316 s.overlord.Settle()317 st.Lock()318 c.Assert(chg.Err(), IsNil)319 // and check the snap got correctly installed320 c.Check(osutil.FileExists(filepath.Join(dirs.SnapMountDir, "foo", "128", "meta", "snap.yaml")), Equals, true)321 // and check the snap got correctly installed322 c.Check(osutil.FileExists(filepath.Join(dirs.SnapMountDir, "bar", "65", "meta", "snap.yaml")), Equals, true)323 // verify324 r, err := os.Open(dirs.SnapStateFile)325 c.Assert(err, IsNil)326 state, err := state.ReadState(nil, r)327 c.Assert(err, IsNil)328 state.Lock()329 defer state.Unlock()330 // check foo331 info, err := snapstate.CurrentInfo(state, "foo")332 c.Assert(err, IsNil)333 c.Check(info.SnapID, Equals, "foosnapidsnapid")334 c.Check(info.Revision, Equals, snap.R(128))335 pubAcct, err := assertstate.Publisher(st, info.SnapID)336 c.Assert(err, IsNil)337 c.Check(pubAcct.AccountID(), Equals, "developerid")338 // check bar339 info, err = snapstate.CurrentInfo(state, "bar")340 c.Assert(err, IsNil)341 c.Check(info.SnapID, Equals, "barsnapidsnapid")342 c.Check(info.Revision, Equals, snap.R(65))343 pubAcct, err = assertstate.Publisher(st, info.SnapID)344 c.Assert(err, IsNil)345 c.Check(pubAcct.AccountID(), Equals, "developerid")346}347func (s *FirstBootTestSuite) makeModelAssertion(c *C, modelStr string, reqSnaps ...string) *asserts.Model {348 headers := map[string]interface{}{349 "series": "16",350 "authority-id": "my-brand",351 "brand-id": "my-brand",352 "model": modelStr,353 "architecture": "amd64",354 "store": "canonical",355 "gadget": "pc",356 "kernel": "pc-kernel",357 "timestamp": time.Now().Format(time.RFC3339),358 }359 if len(reqSnaps) != 0 {360 reqs := make([]interface{}, len(reqSnaps))361 for i, req := range reqSnaps {362 reqs[i] = req363 }364 headers["required-snaps"] = reqs365 }366 model, err := s.brandSigning.Sign(asserts.ModelType, headers, nil, "")367 c.Assert(err, IsNil)368 return model.(*asserts.Model)369}370func (s *FirstBootTestSuite) makeModelAssertionChain(c *C, reqSnaps ...string) []asserts.Assertion {371 assertChain := []asserts.Assertion{}372 brandAcct := assertstest.NewAccount(s.storeSigning, "my-brand", map[string]interface{}{373 "account-id": "my-brand",374 "verification": "certified",375 }, "")376 assertChain = append(assertChain, brandAcct)377 brandAccKey := assertstest.NewAccountKey(s.storeSigning, brandAcct, nil, s.brandPrivKey.PublicKey(), "")378 assertChain = append(assertChain, brandAccKey)379 model := s.makeModelAssertion(c, "my-model", reqSnaps...)380 assertChain = append(assertChain, model)381 storeAccountKey := s.storeSigning.StoreAccountKey("")382 assertChain = append(assertChain, storeAccountKey)383 return assertChain384}385func (s *FirstBootTestSuite) TestImportAssertionsFromSeedHappy(c *C) {386 ovld, err := overlord.New()387 c.Assert(err, IsNil)388 st := ovld.State()389 // add a bunch of assert files390 assertsChain := s.makeModelAssertionChain(c)391 for i, as := range assertsChain {392 fn := filepath.Join(dirs.SnapSeedDir, "assertions", strconv.Itoa(i))393 err := ioutil.WriteFile(fn, asserts.Encode(as), 0644)394 c.Assert(err, IsNil)395 }396 // import them397 st.Lock()398 defer st.Unlock()399 model, err := devicestate.ImportAssertionsFromSeed(st)400 c.Assert(err, IsNil)401 c.Assert(model, NotNil)402 // verify that the model was added403 db := assertstate.DB(st)404 as, err := db.Find(asserts.ModelType, map[string]string{405 "series": "16",406 "brand-id": "my-brand",407 "model": "my-model",408 })409 c.Assert(err, IsNil)410 _, ok := as.(*asserts.Model)411 c.Check(ok, Equals, true)412 ds, err := auth.Device(st)413 c.Assert(err, IsNil)414 c.Check(ds.Brand, Equals, "my-brand")415 c.Check(ds.Model, Equals, "my-model")416 c.Check(model.BrandID(), Equals, "my-brand")417 c.Check(model.Model(), Equals, "my-model")418}419func (s *FirstBootTestSuite) TestImportAssertionsFromSeedMissingSig(c *C) {420 st := s.overlord.State()421 st.Lock()422 defer st.Unlock()423 // write out only the model assertion424 assertsChain := s.makeModelAssertionChain(c)425 for _, as := range assertsChain {426 if as.Type() == asserts.ModelType {427 fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model")428 err := ioutil.WriteFile(fn, asserts.Encode(as), 0644)429 c.Assert(err, IsNil)430 break431 }432 }433 // try import and verify that its rejects because other assertions are434 // missing435 _, err := devicestate.ImportAssertionsFromSeed(st)436 c.Assert(err, ErrorMatches, "cannot find account-key .*: assertion not found")437}438func (s *FirstBootTestSuite) TestImportAssertionsFromSeedTwoModelAsserts(c *C) {439 st := s.overlord.State()440 st.Lock()441 defer st.Unlock()442 // write out two model assertions443 model := s.makeModelAssertion(c, "my-model")444 fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model")445 err := ioutil.WriteFile(fn, asserts.Encode(model), 0644)446 c.Assert(err, IsNil)447 model2 := s.makeModelAssertion(c, "my-second-model")448 fn = filepath.Join(dirs.SnapSeedDir, "assertions", "model2")449 err = ioutil.WriteFile(fn, asserts.Encode(model2), 0644)450 c.Assert(err, IsNil)451 // try import and verify that its rejects because other assertions are452 // missing453 _, err = devicestate.ImportAssertionsFromSeed(st)454 c.Assert(err, ErrorMatches, "cannot add more than one model assertion")455}456func (s *FirstBootTestSuite) TestImportAssertionsFromSeedNoModelAsserts(c *C) {457 st := s.overlord.State()458 st.Lock()459 defer st.Unlock()460 assertsChain := s.makeModelAssertionChain(c)461 for _, as := range assertsChain {462 if as.Type() != asserts.ModelType {463 fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model")464 err := ioutil.WriteFile(fn, asserts.Encode(as), 0644)465 c.Assert(err, IsNil)466 break467 }468 }469 // try import and verify that its rejects because other assertions are470 // missing471 _, err := devicestate.ImportAssertionsFromSeed(st)472 c.Assert(err, ErrorMatches, "need a model assertion")473}...

Full Screen

Full Screen

structs.go

Source:structs.go Github

copy

Full Screen

1package tort2import (3 "fmt"4 "reflect"5 "strconv"6)7// StructAssertions test object properties.8type StructAssertions struct {9 Assertions10 name string11 obj interface{}12 isnil bool13}14// Struct identifies assertions about an object.15func (assert Assertions) Struct(obj interface{}) StructAssertions {16 assert.t.Helper()17 kind := reflect.ValueOf(obj).Kind()18 var isnil bool19 if kind == reflect.Ptr {20 kind = reflect.TypeOf(obj).Elem().Kind()21 isnil = reflect.ValueOf(obj).IsNil()22 }23 if kind != reflect.Struct {24 assert.Fatal("%v is not a struct %d/%d", obj, kind, reflect.Struct)25 }26 return StructAssertions{27 Assertions: assert,28 name: "struct",29 obj: obj,30 isnil: isnil,31 }32}33// Struct identifies assertions about an object and returns the assertions around the struct.34func (assert StructAssertions) Struct(field string) StructAssertions {35 assert.t.Helper()36 name := fmt.Sprintf("%s.%s", assert.Type(), field)37 property := assert.Field(field)38 if property.Kind() != reflect.Struct {39 assert.Fatal("field %s is not a struct", name)40 }41 return StructAssertions{42 Assertions: assert.Assertions,43 name: name,44 obj: property.Interface(),45 }46}47// Struct looks up an element in a slice expecting it to be a struct or a pointer to a struct.48func (assert SliceAssertions) Struct(idx int) StructAssertions {49 assert.t.Helper()50 name := strconv.Itoa(idx)51 property := assert.Element(idx)52 kind := property.Kind()53 var isnil bool54 if kind == reflect.Ptr {55 kind = property.Type().Elem().Kind()56 isnil = property.IsNil()57 }58 if kind != reflect.Struct {59 assert.Fatal("%v is not a struct %d/%d", property.Interface(), kind, reflect.Struct)60 }61 return StructAssertions{62 Assertions: assert.Assertions,63 name: name,64 obj: property.Interface(),65 isnil: isnil,66 }67}68// Type returns the name of the struct.69func (assert StructAssertions) Type() string {70 assert.t.Helper()71 kind := reflect.ValueOf(assert.obj).Kind()72 if kind == reflect.Ptr {73 return reflect.TypeOf(assert.obj).Elem().Name()74 }75 return reflect.TypeOf(assert.obj).Name()76}77// Field verifies a field exists and returns it.78func (assert StructAssertions) Field(name string) reflect.Value {79 assert.t.Helper()80 value := reflect.ValueOf(assert.obj)81 field := value.FieldByName(name)82 return field83}84// IsNil returns true if the object was nil.85func (assert StructAssertions) IsNil() {86 assert.t.Helper()87 if !assert.isnil {88 assert.Failed("%s is not nil", assert.Type())89 }90}91// IsNotNil returns true if the object was nil.92func (assert StructAssertions) IsNotNil() {93 assert.t.Helper()94 if assert.isnil {95 assert.Failed("%s is nil", assert.Type())96 }97}...

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var i interface{}4 fmt.Println(assertions.IsNil(i))5}6import (7func main() {8 var i interface{}9 fmt.Println(assert.IsNil(i))10}11import (12func main() {13 var i interface{}14 fmt.Println(assertions.IsNil(i))15}16import (17func main() {18 var i interface{}19 fmt.Println(assertions.IsNil(i))20}21import (22func main() {23 var i interface{}24 fmt.Println(assertions.IsNil(i))25}26import (27func main() {28 var i interface{}29 fmt.Println(assertions.IsNil(i))30}31import (32func main() {33 var i interface{}34 fmt.Println(assertions.IsNil(i))35}36import (37func main() {38 var i interface{}39 fmt.Println(assertions.IsNil(i))40}41import (42func main() {43 var i interface{}44 fmt.Println(assertions.IsNil(i))45}46import

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1func TestNil(t *testing.T) {2 assert.Nil(t, s)3}4func TestNotNil(t *testing.T) {5 assert.NotNil(t, s)6}7func TestEmpty(t *testing.T) {8 assert.Empty(t, "")9}10func TestNotEmpty(t *testing.T) {11 assert.NotEmpty(t, "")12}13func TestTrue(t *testing.T) {14 assert.True(t, true)15}16func TestFalse(t *testing.T) {17 assert.False(t, true)18}19func TestContains(t *testing.T) {20 assert.Contains(t, "Hello World", "World")21}22func TestNotContains(t *testing.T) {23 assert.NotContains(t, "Hello World", "World")24}25func TestContains(t *testing.T) {26 assert.Contains(t, "Hello World", "World")27}28func TestNotContains(t *testing.T) {29 assert.NotContains(t, "Hello World", "World")30}31func TestContains(t *testing.T) {32 assert.Contains(t, "Hello World", "World")33}34func TestNotContains(t *testing.T) {35 assert.NotContains(t, "Hello World", "World")36}37func TestContains(t *testing.T) {38 assert.Contains(t, "Hello World", "World")39}

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1import (2func TestNil(t *testing.T) {3 var a interface{}4 assert.True(t, assert.IsNil(t, a))5}6import (7func TestNil(t *testing.T) {8 var a interface{}9 assert.True(t, assert.IsNil(t, a))10}11import (12func TestNil(t *testing.T) {13 var a interface{}14 assert.True(t, assert.IsNil(t, a))15}16import (17func TestNil(t *testing.T) {18 var a interface{}19 assert.True(t, assert.IsNil(t, a))20}21import (22func TestNil(t *testing.T) {23 var a interface{}24 assert.True(t, assert.IsNil(t, a))25}26import (27func TestNil(t *testing.T) {28 var a interface{}29 assert.True(t, assert.IsNil(t, a))30}31import (32func TestNil(t *testing.T) {33 var a interface{}34 assert.True(t, assert.IsNil(t, a))35}36import (37func TestNil(t *testing.T) {38 var a interface{}39 assert.True(t, assert.IsNil(t, a))40}41import (42func TestNil(t *testing.T) {

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1import (2func TestNil(t *testing.T) {3 assert.True(t, assert.IsNil(t, a))4}5import (6func TestNil(t *testing.T) {7 assert.True(t, assert.IsNil(a))8}9import (10func TestNil(t *testing.T) {11 assert.True(assert.IsNil(a))12}13import (14func TestNil(t *testing.T) {15 assert.True(assert.IsNil(t, a))16}17import (18func TestNil(t *testing.T) {19 assert.True(assert.IsNil(a))20}21import (22func TestNil(t *testing.T) {23 assert.True(assert.IsNil(t, a))24}25import (26func TestNil(t *testing.T) {27 assert.True(assert.IsNil(a))28}29import (30func TestNil(t *testing.T) {31 assert.True(assert.IsNil(t, a))32}33import (34func TestNil(t *testing.T) {35 assert.True(assert.IsNil(a))36}37import (

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var i interface{}4 fmt.Println(assertions.IsNil(i))5}6func IsNotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool7import (8func main() {9 var i interface{}10 fmt.Println(assertions.IsNotNil(i))11}12import (13func main() {14 fmt.Println(assertions.IsNotNil(i))15}16func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool17import (18func main() {19 var i interface{}20 fmt.Println(assertions.IsType(i, "string"))21}

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 assert.Nil(a)4 assert.NotNil(b)5 fmt.Println("done")6}

Full Screen

Full Screen

isNil

Using AI Code Generation

copy

Full Screen

1import  (2func  TestIsNil(t *testing.T)  {3var  i interface{}4assert.Nil(t, i)5assert.True(t, assert.IsType(t, nil, i))6assert.True(t, assert.IsType(t, (*int)(nil), i))7assert.True(t, assert.IsType(t, (*int)(nil), (*int)(nil)))8}9import  (10func  TestIsNil(t *testing.T)  {11var  i interface{}12assert.Nil(t, i)13assert.True(t, assert.IsType(t, nil, i))14assert.True(t, assert.IsType(t, (*int)(nil), i))15assert.True(t, assert.IsType(t, (*int)(nil), (*int)(nil)))16}17import  (18func  TestIsNil(t *testing.T)  {19var  i interface{}20assert.Nil(t, i)21assert.True(t, assert.IsType(t, nil, i))22assert.True(t, assert.IsType(t, (*int)(nil), i))23assert.True(t, assert.IsType(t, (*int)(nil), (*int)(nil)))24}25import  (26func  TestIsNil(t *testing.T)  {27var  i interface{}28assert.Nil(t, i)29assert.True(t, assert.IsType(t, nil, i))30assert.True(t, assert.IsType(t, (*int)(nil), i))31assert.True(t, assert.IsType(t, (*int)(nil), (*int)(nil)))32}33import  (34func  TestIsNil(t *testing.T)  {35var  i interface{}36assert.Nil(t, i)37assert.True(t, assert.IsType(t, nil, i))38assert.True(t, assert.IsType(t, (*int)(nil), i))39assert.True(t, assert.IsType(t, (*int)(nil), (*int)(nil)))40}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Venom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful