Skip to content

Commit

Permalink
测试
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Dec 24, 2024
1 parent 4ded002 commit ef2535d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 2 deletions.
1 change: 0 additions & 1 deletion assets/demo.js

This file was deleted.

13 changes: 13 additions & 0 deletions core/controller/template_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package controller

import (
"testing"
)

func TestGenTemplate(t *testing.T) {
modelName := "TestModel"
template := GenTemplate(modelName)
if template == "" {
t.Error("Expected non-empty template")
}
}
12 changes: 12 additions & 0 deletions core/curd_orm/gormIns_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package curd_orm

import (
"testing"
)

func TestBootMS(t *testing.T) {
db := BootMS()
if db == nil {
t.Error("Expected a valid database instance")
}
}
9 changes: 8 additions & 1 deletion core/model/generator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package model

import (
"fmt"
)

func Gen(modelName string) error {
template := GenTemplate(modelName)
err := CopyToModelPath(modelName, template)
return err
if err != nil {
return fmt.Errorf("failed to copy to model path: %w", err)
}
return nil
}
29 changes: 29 additions & 0 deletions core/model/template_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package model

import (
"testing"
)

func TestGenTemplate(t *testing.T) {
modelName := "TestModel"
expectedTemplate := `
package models
import (
"github.com/goravel/framework/database/orm"
)
type TestModel struct {
orm.Model
orm.SoftDeletes
}
`
// Generate the template
template := GenTemplate(modelName)

// Check if the generated template matches the expected template
if template != expectedTemplate {
t.Errorf("Expected template:\n%s\nGot:\n%s", expectedTemplate, template)
}
}
1 change: 1 addition & 0 deletions facades/crud.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package facades

import (
crud "goravel/packages/goravel-crud"
"log"

"goravel/packages/goravel-crud/contracts"
Expand Down
1 change: 1 addition & 0 deletions test_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go tool cover -func=coverage.out | grep total | awk '{print $3}'
12 changes: 12 additions & 0 deletions tests/model/test_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package model

import (
"github.com/goravel/framework/database/orm"
)

type TestModel struct {
orm.Model
Username string `gorm:"column:username" form:"username" json:"username"`
Password string `gorm:"column:password" form:"password" json:"password"`
orm.SoftDeletes
}

0 comments on commit ef2535d

Please sign in to comment.