volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

missing code in model_test.go with --templates flag #322

Closed saulortega closed 6 years ago

saulortega commented 6 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v3.0.0-rc9

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler psql -d --templates /home/cubitix/go/src/github.com/volatiletech/sqlboiler/templates

This happens only using the --templates flag.

Actual and full code generated:

// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package models

import (
    "bytes"
    "reflect"
    "testing"

    "github.com/volatiletech/sqlboiler/boil"
    "github.com/volatiletech/sqlboiler/queries"
    "github.com/volatiletech/sqlboiler/randomize"
    "github.com/volatiletech/sqlboiler/strmangle"
)

func testAssetCategoriesUpsert(t *testing.T) {
    t.Parallel()

    if len(assetCategoryColumns) == len(assetCategoryPrimaryKeyColumns) {
        t.Skip("Skipping table with only primary key columns")
    }

    seed := randomize.NewSeed()
    var err error
    // Attempt the INSERT side of an UPSERT
    o := AssetCategory{}
    if err = randomize.Struct(seed, &o, assetCategoryDBTypes, true); err != nil {
        t.Errorf("Unable to randomize AssetCategory struct: %s", err)
    }

    tx := MustTx(boil.Begin())
    defer func() { _ = tx.Rollback() }()
    if err = o.Upsert(tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
        t.Errorf("Unable to upsert AssetCategory: %s", err)
    }

    count, err := AssetCategories().Count(tx)
    if err != nil {
        t.Error(err)
    }
    if count != 1 {
        t.Error("want one record, got:", count)
    }

    // Attempt the UPDATE side of an UPSERT
    if err = randomize.Struct(seed, &o, assetCategoryDBTypes, false, assetCategoryPrimaryKeyColumns...); err != nil {
        t.Errorf("Unable to randomize AssetCategory struct: %s", err)
    }

    if err = o.Upsert(tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
        t.Errorf("Unable to upsert AssetCategory: %s", err)
    }

    count, err = AssetCategories().Count(tx)
    if err != nil {
        t.Error(err)
    }
    if count != 1 {
        t.Error("want one record, got:", count)
    }
}
aarondl commented 6 years ago

This is also working as intended. Remember that the templates directory does not contain any tests. Use --templates templates --templates templates_test to additionally include the templates test dir.

saulortega commented 6 years ago

Oh, you're right.