测试Go模型

So this is one of my Go models:

type ObjectReference struct {
IRI           string    `json:"iri" bson:"iri"`
ObjectType    string    `json:"objectType" bson:"objectType,omitempty"`
ActivityType  string    `json:"activityType,omitempty" bson:"activityType,omitempty"`
Errors                  `bson:"-"`

}

I have a validation on the ActivityType as:

   objTypeSuccess := o.ObjectType == "activity"
success = success && objTypeSuccess
if (!objTypeSuccess) {
    o.errors = append(o.errors, "Object objectType supplied : " + o.ObjectType + " is invalid. Valid object types are : [activity]")
}

where

o *ObjectReference is in the func() definition 

I am trying to write a test as so:

        testObj = models.ObjectReference{
        // Invalid Obj Type
        IRI: "http://localhost:8001/launched",
        ObjectType: ????,
        ActivityType: testObjType,
    }

I don't quite understand how I could initialize the ObjectType in my testObj. Can someone help me with this?

The ObjectReference.ObjectType is a field of type string. That being said you can initialize it with an expression of type string. The most basic/simple expression of type string is a string literal such as "hello".

Since in your test code you compare it to the value "activity", I assume that is what you want to initialize it with. You can do that like this:

testObj = models.ObjectReference{
    IRI: "http://localhost:8001/launched",
    ObjectType: "activity",
    ActivityType: testObjType,
}

But of course you can specify any other values/expressions of type stirng:

testObj = models.ObjectReference{
    IRI: "http://localhost:8001/launched",
    ObjectType: "NOT-AN-ACTIVITY",
    ActivityType: testObjType,
}