dimanche 12 avril 2020

How to solve undefined structs while testing go code?

I havce the following main package:

package main

import "fmt"

type bot interface {
    getGretting() string
}

type englishBot struct{}

func main() {
    eb := englishBot{}

    printGreeting(eb)
}

func printGreeting(b bot) {
    fmt.Println(b.getGretting())
}

func (englishBot) getGretting() string {
    return "Hi there!"
}

And I'm trying to test my getGretting() function like this:

package main

import (
    "github.com/smartystreets/assertions"
    "github.com/smartystreets/assertions/should"
    "testing"
)

func Test_should_return_hi_there(t *testing.T) {
    //Arrange
    assert := assertions.New(t)

    eb := englishBot{}

    //Act
    result := eb.getGretting()

    //Assert
    assert.So(result, should.Equal, "Hi there!")
}

But every time I try to run this test I get the same error:

# command-line-arguments [command-line-arguments.test] .\main_test.go:13:11: undefined: englishBot

How can I solve this?

Aucun commentaire:

Enregistrer un commentaire