packageprototypevarDocManger=DocManagement{farSample:FAR{Content:"This is a FAR Doc"},srsSample:SRS{Content:"This is a SRS Doc"},}typeDocManagementstruct{farSampleFARsrsSampleSRS}func(mDocManagement)GetOfficialDocument(docTypestring)OfficialDocumentFormer{switchdocType{case"far":returnm.farSample.Clone()case"srs":returnm.srsSample.Clone()default:returnnil}}typeOfficialDocumentFormerinterface{Clone()OfficialDocumentFormerDisplay()}typeFARstruct{Contentstring}func(fFAR)Clone()OfficialDocumentFormer{varnewFARFARd,_:=json.Marshal(f)_=json.Unmarshal(d,&newFAR)newFAR.Display()returnnewFAR}func(fFAR)Display(){println("==== FAR Doc ====")fmt.Printf("%+v\n",f)println("==== FAR Doc ====")}typeSRSstruct{Contentstring}func(sSRS)Clone()OfficialDocumentFormer{varnewSRSSRSd,_:=json.Marshal(s)_=json.Unmarshal(d,&newSRS)newSRS.Display()returnnewSRS}func(sSRS)Display(){println("==== SRS Doc ====")fmt.Printf("%+v\n",s)println("==== SRS Doc ====")}
funcTestDocManagement_GetOfficialDocument(t*testing.T){typefieldsstruct{farSampleFARsrsSampleSRS}typeargsstruct{docTypestring}tests:=[]struct{namestringfieldsfieldsargsargswantOfficialDocumentFormer}{// TODO: Add test cases.{name:"far test",fields:fields{farSample:DocManger.farSample,srsSample:DocManger.srsSample,},args:args{docType:"far"},want:FAR{Content:"This is a FAR Doc"},},{name:"srs test",fields:fields{farSample:DocManger.farSample,srsSample:DocManger.srsSample,},args:args{docType:"srs"},want:SRS{Content:"This is a SRS Doc"},},}for_,tt:=rangetests{t.Run(tt.name,func(t*testing.T){m:=DocManagement{farSample:tt.fields.farSample,srsSample:tt.fields.srsSample,}ifgot:=m.GetOfficialDocument(tt.args.docType);!reflect.DeepEqual(got,tt.want){t.Errorf("GetOfficialDocument() = %v, want %v",got,tt.want)}})}}