Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is this testing? I can't get this library to actual fail a test. #19

Open
rhugga opened this issue Dec 13, 2019 · 1 comment
Open

Comments

@rhugga
Copy link

rhugga commented Dec 13, 2019

func SetupTests(t *testing.T) *gorm.DB {
	mocket.Catcher.Register()
	mocket.Catcher.Logging = true
	db, err := gorm.Open(mocket.DriverName, "connection_string")
	if err != nil {
		t.Fatalf(err.Error())
	}
	return db
}

func TestInsertStoragePool(t *testing.T) {

	cases := []struct {
		givenPool    StoragePool
                wantedError error
	}{
		{ // happy path
			givenPool: StoragePool{
				Name:   "POOL1",
				PoolId: "1",
				Type:   "NetworkFilesystem",
				Volumes: []Volume{
					{
						Name:          "VOL01",
						StorageId:     "1",
						Type:          "ROOT",
						VolumeId:      "1",
					},

				},
			},
			wantedError: nil,
		},
	}

	for _, c := range cases {
		db := SetupTests(t)
		db.LogMode(true)
		reply := []map[string]interface{}{{"id": 5}}
		mocket.Catcher.Reset().NewMock().WithQuery("INSERT INTO \"storage_pools\"").WithID(int64(5)).WithArgs(c.givenPool).WithReply(reply)
		err := InsertStoragePool(db, &c.givenPool)
		if err != nil {
			t.Error(err)
		}
		fmt.Fprintf(os.Stderr, "\nPOOLID=%d\n", c.givenPool.ID)
	}
}

What is this testing?

  1. The primary key is getting set to 5577006791947779410, not 5.
  2. The WithReply is apparently not doing anything because this is not failing.
  3. My Type column above is an enumerated type. When I set the Type to an invalid value, this test still succeeds in flying colors.

According to go test, this test succeeds with flying colors.

@tokamak-hf
Copy link

I found something similar, for testing set the expected query to just UPDATE while the underlying query is an INSERT statement. the test still passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants