我正在结构内传递结构数组,在单元测试中,我使用了ServiceAccounts的dto和我的测试代码TestStoreServiceAccounts。如何在结构内传递结构数组?结构的嵌套是我无法理解的。
func TestStoreServiceAccounts(t *testing.T) {
StoreServiceAccounts = func(serviceAccounts []models.ServiceAccount) ([]string, error) {
ServiceAccounts := []string{"service-account-details-inserted"}
return ServiceAccounts, nil
}
Data := dto.ServiceAccountRequestDTO{
ServiceAccounts : []{ //error on this line
WorkspaceID: 1,
ServiceAccountName: "sa-10",
ServiceAccountKey: dto.ServiceAccountKey{
Type: "service_account",
ProjectID: "abc",
PrivateKeyID: "123",
PrivateKey: "234",
ClientEmail: "read-clusters",
ClientID: "cdf",
AuthURI: "https://accounts.google.com/o/oaut",
TokenURI: "https://oauth2.googleapis.com/token",
AuthProviderX509CertURL: "https://www.googleapis.com",
ClientX509CertURL: "xwy",
},
CreatedAt: "2021-03-08 17:05:21.0",
UpdatedAt: "2021-03-08 17:05:21.0",
CreatedBy: "user-01",
UpdatedBy: "user-01",
},
}
responseData, err := clusterService.StoreServiceAccountsService(context.Background(), Data)
serviceAccountsdata := []string{"service-account-details-inserted"}
assert.Nil(t, err)
assert.NotNil(t, responseData)
assert.EqualValues(t, serviceAccountsdata, responseData)
}
墨色风雨
相关分类