Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Firas Darwish committed Nov 13, 2024
1 parent 18d0955 commit 8adf896
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ func (c *Container) Name() string {
return c.name
}

func (this *Container) SetName(name string) {
func (this *Container) SetName(name string) *Container {
if name == "" {
panic("container name can not be empty")

Check warning on line 60 in container.go

View check run for this annotation

Codecov / codecov/patch

container.go#L60

Added line #L60 was not covered by tests
}

if this.name == name {
return
return this
}

Check warning on line 65 in container.go

View check run for this annotation

Codecov / codecov/patch

container.go#L64-L65

Added lines #L64 - L65 were not covered by tests

if this.name != "" {
panic("container name already set")
}

this.name = name
return this
}

// Validate invokes all registered resolvers. It panics if any of them fails.
Expand Down
41 changes: 41 additions & 0 deletions ore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ func TestIsSeal(t *testing.T) {
}
}

func TestContainerName(t *testing.T) {
if got := Name(); got != "DEFAULT" {
t.Errorf("Name() = %v; want %v", got, "DEFAULT")
}
}

func TestContainerSetName(t *testing.T) {
con := NewContainer().SetName("ORE")
if got := con.Name(); got != "ORE" {
t.Errorf("Name() = %v; want %v", got, "ORE")
}
}

func TestNewContainerName(t *testing.T) {
con := NewContainer()
if got := con.Name(); got != "" {
t.Errorf("Name() = `%v`; want `%v`", got, "")
}
}

func TestContainerReSetName(t *testing.T) {
con := NewContainer().SetName("ORE")
assert.Panics(t, func() {
con.SetName("ORE1")
})
}

func TestContainerID(t *testing.T) {
if got := ContainerID(); got != 1 {
t.Errorf("ContainerID() = %v; want 1", got)
}
}

func TestNewContainerIDSerial(t *testing.T) {
clearAll()
con := NewContainer()
if got := con.ContainerID(); got != 2 {
t.Errorf("ContainerID() = %v; want 2", got)
}
}

type A1 struct{}
type A2 struct{}

Expand Down

0 comments on commit 8adf896

Please sign in to comment.